Files
dev-tools/common/createApolloClient.js
Exponent GitHub Bot e3f6a67ce5 Initial commit
fbshipit-source-id: 04f171ad7fc354fbc437cd07abdee445323d9a0f
2018-07-17 18:51:11 +00:00

27 lines
876 B
JavaScript

import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
import { WebSocketLink } from 'apollo-link-ws';
import fetch from 'isomorphic-fetch';
import getConfig from 'next/config';
import introspectionQueryResultData from '../fragmentTypes.json';
export default function createApolloClient(subscriptionClient) {
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
});
return new ApolloClient({
link: new WebSocketLink(subscriptionClient),
cache: new InMemoryCache({ dataIdFromObject, fragmentMatcher }),
});
}
function dataIdFromObject(object) {
// If the object has a field named `id`, it must be a globally unique ID.
if (object.id !== undefined) {
return object.id;
}
return null;
}