Created
July 16, 2019 02:20
-
-
Save blorenz/21e1913ea4f7c0a9a0a1085d597fdbd0 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 { 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