Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.16 KB

DOCS.mdx

File metadata and controls

63 lines (43 loc) · 1.16 KB

import { PlayGround } from 'react-display-window/lib/components'; import Example from './src/docs/Example'; import BuiltWith from './src/docs/BuiltWith';

Apollo Link Computed

More info is available on Github.

Example

Setup

Install it as any other npm package:

$ npm i apollo-link-computed

Next, add it to your apollo client:

import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { ApolloLink } from 'apollo-link';
import { setContext } from 'apollo-link-context';
import { withClientState } from 'apollo-link-computed';

import resolvers from './resolvers';


const TokenLink = () => setContext(() => {
  return {
    headers: {
      'Authorization': 'Token',
    },
  };
});

const cache = new InMemoryCache();

const link = ApolloLink.from([
  TokenLink(),
  withClientState({
    resolvers,
    cache,
  }),
  new HttpLink({
    uri: 'http://my-api-host/graphql',
    credentials: 'same-origin'
  }),
]);

export default new ApolloClient({ link, cache });