Last active
May 5, 2018 13:50
-
-
Save komkanit/2a1203815bbfc4a6423a2fe727612ab3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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