mirror of
https://github.com/expo/expo-cli.git
synced 2026-11-15 03:58:07 -10:00
24 lines
756 B
JavaScript
24 lines
756 B
JavaScript
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
|
|
import { ApolloClient } from 'apollo-client';
|
|
import { WebSocketLink } from 'apollo-link-ws';
|
|
|
|
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;
|
|
}
|