Skip to content

Instantly share code, notes, and snippets.

@komkanit
Last active May 5, 2018 13:50
Show Gist options
  • Save komkanit/2a1203815bbfc4a6423a2fe727612ab3 to your computer and use it in GitHub Desktop.
Save komkanit/2a1203815bbfc4a6423a2fe727612ab3 to your computer and use it in GitHub Desktop.
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { onError } from 'apollo-link-error'; //add apollo error link
import { ApolloLink } from 'apollo-link'; // add apollo link
const httpLink = new HttpLink({
uri: 'http://localhost:8080/graphql',
});
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
),
);
}
if (networkError) {
redirect('/error');
}
});
const client = new ApolloClient({
link: ApolloLink.from([errorLink, httpLink]), // combine errorLink and httpLink
cache: new InMemoryCache(),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment