How to use the apollo/client function in apollo

To help you get started, we’ve selected a few apollo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github staylor / graphql-wordpress / packages / draft / src / client / apolloClient.js View on Github external
import { InMemoryCache } from 'apollo-cache-inmemory';
import Cookies from 'js-cookie';
import fragmentMatcher from 'tools/fragmentMatcher';
import { TOKEN_KEY } from 'utils/constants';
import apolloClient from 'apollo/client';

const headers = {};
const authToken = Cookies.get(TOKEN_KEY);
if (authToken) {
  headers.Authorization = `Bearer ${authToken}`;
}

export default apolloClient('/graphql', headers, {
  cache: new InMemoryCache({ fragmentMatcher }).restore(window.__APOLLO_STATE__),
});
github staylor / graphql-wordpress / packages / draft / src / server / router / apolloClient.js View on Github external
export default (req, res, next) => {
  const port = parseInt(KYT.SERVER_PORT, 10);
  const uri = `http://localhost:${port}/graphql`;
  const headers = {};
  if (req.cookies.draftAuthToken) {
    headers.Authorization = `Bearer ${req.cookies.draftAuthToken}`;
  }

  res.locals.client = apolloClient(uri, headers, { ssrMode: true });

  next();
};