Last active
September 25, 2019 11:24
-
-
Save mxmzb/17c377b40130aa1dff20b6c37573f647 to your computer and use it in GitHub Desktop.
Apollo link
This file contains hidden or 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 { ApolloClient } from "apollo-client"; | |
import link from "./apolloLink"; | |
const client = new ApolloClient({ | |
link, | |
}); | |
export default client; |
This file contains hidden or 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 { ApolloLink } from "apollo-link"; | |
import { onError } from "apollo-link-error"; | |
import { HttpLink } from "apollo-link-http"; | |
import fetch from "unfetch"; | |
const errorLink = onError(({ graphQLErrors, networkError }) => { | |
if (graphQLErrors) | |
graphQLErrors.map(({ message, locations, path }) => | |
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`), | |
); | |
if (networkError) console.log(`[Network error]: ${networkError}`); | |
}); | |
const link = ApolloLink.from([ | |
errorLink, | |
new HttpLink({ uri: env.ENDPOINT_URL, fetch }), | |
]); | |
export default link; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment