Skip to content

Instantly share code, notes, and snippets.

@ghankerson
Created May 30, 2019 21:44
Show Gist options
  • Save ghankerson/06b3b967fbd9c33b5c876534da3839e4 to your computer and use it in GitHub Desktop.
Save ghankerson/06b3b967fbd9c33b5c876534da3839e4 to your computer and use it in GitHub Desktop.
import fetch from 'cross-fetch';
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import FragmentMatcher from './FragmentMatcher';
const cache = new InMemoryCache({ fragmentMatcher: FragmentMatcher }).restore(window.__APOLLO_STATE__);
export function client(graphqlEnv) {
return new ApolloClient({
ssrForceFetchDelay: 100,
cache,
link: createHttpLink({
uri: `https://cmsproxy${graphqlEnv}.publicradio.org/api/v1/graphql`,
fetch: fetch
}),
cacheRedirects: {
Query: {
episode: (_, { id }, { getCacheKey }) => getCacheKey({ id, __typename: 'Episode' })
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment