Skip to content

czystyl/apollo-link-computed-property

Repository files navigation

apollo-link-computed-property

This project is under heavy active development !!

Version downloads PRs Welcome MIT License

Introduction

Apollo link for @computed directive support on client side.

Check this directive for the server side.

Table of Contents

Installation

yarn add apollo-link-computed-property

This package requires apollo-client as peer dependency

Usage

const httpLink = createHttpLink({ uri: 'http://you-graphql-server/graphql' });

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: ApolloLink.from([ComputedPropertyLink, httpLink]),
});

Query:

client.query({
  query: gql`
    {
      me {
        firstName
        lastName
        fullName @computed(value: "$me.firstName $me.lastName")
      }
    }
  `,
});

Directive Parameters

Directive params:

value: String

The computed value. It can contain fields defined within the current type.

Remember to add prefix with the name of query root level

Example:

@computed(value: "$me.firstName $me.lastName") @computed(value: "$product.price $")

Contributing

I would love to see your contribution. ❤️

For local development (and testing), all you have to do is to run yarn and then run server yarn start:server and client yarn start:client. That will start the Apollo server with client and you are ready to contribute 🎉

Run yarn test (try --watch flag) for unit tests (we are using Jest)

TODO:

  • Add types
  • Support for computing nested fields
  • Support fragments

LICENSE

The MIT License (MIT) 2018 - Luke Czyszczonik - mailto:lukasz.czyszczonik@gmail.com

About

Apollo link for computed property directive for client side

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published