apollo-link-computed-property icon indicating copy to clipboard operation
apollo-link-computed-property copied to clipboard

Apollo link for computed property directive for client side

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

  • Introduction
  • Installation
  • Usage
  • Parameters
  • Contributing
  • TODO
  • LICENSE

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 :tada:

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

TODO:

  • [ ] Add types
  • [x] Support for computing nested fields
  • [ ] Support fragments

LICENSE

The MIT License (MIT) 2018 - Luke Czyszczonik - mailto:[email protected]