12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /**
- * Using next-with-apollo
- * https://github.com/lfades/next-with-apollo
- *
- * Changes:
- * * Reading endpoint and prodEndpoint from a config file
- * * Setting request to handle credentials.
- */
- import withApollo from 'next-with-apollo'
- import { ApolloClient } from 'apollo-client'
- import { ApolloLink } from 'apollo-link'
- import { InMemoryCache } from 'apollo-cache-inmemory'
- import { HttpLink } from 'apollo-link-http'
- import { onError } from 'apollo-link-error'
- const cache = new InMemoryCache()
- const httpLink = new HttpLink({ uri: 'http://localhost:8801/', credentials: 'include' })
- const errorLink = onError(({ graphQLErrors, networkError, response }) => {
- console.log('ERRORS', 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,
- httpLink
- ])
- function createClient ({ ctx, headers }) {
- return new ApolloClient({
- link,
- cache
- })
- }
- export default withApollo(createClient)
|