Skip to content

Instantly share code, notes, and snippets.

@blorenz
Created July 16, 2019 02:20
Show Gist options
  • Save blorenz/21e1913ea4f7c0a9a0a1085d597fdbd0 to your computer and use it in GitHub Desktop.
Save blorenz/21e1913ea4f7c0a9a0a1085d597fdbd0 to your computer and use it in GitHub Desktop.
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
import { createUploadLink } from 'apollo-upload-client';
import React from 'react';
import { ApolloProvider } from 'react-apollo';
import ReactDOM from 'react-dom';
const client = new ApolloClient({
cache: new InMemoryCache().restore(apolloState),
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
// eslint-disable-next-line no-console
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
),
);
// eslint-disable-next-line no-console
if (networkError) console.log(`[Network error]: ${networkError}`);
}),
// Allows us to upload files through mutations, must be lsited after onError
createUploadLink({
credentials: 'include',
uri: resolveHref({ path: '/graphql' }),
}),
]),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment