/**
 * 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 { withData } from 'next-apollo'
// import { HttpLink } from 'apollo-boost'
import { ApolloLink } from 'apollo-link'
import { onError } from 'apollo-link-error'

import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import fetch from 'isomorphic-unfetch'

const client = new ApolloClient({
  link: ApolloLink.from([
    onError(errors => {
      console.log(errors)
      if (errors && errors.response && errors.response.errors) {
        // errors.response.errors = null
      }
    }),
    new HttpLink({
      uri: 'http://localhost:8801/graphql',
      credentials: 'include',
      fetch
    })
  ]),
  cache: new InMemoryCache()
})

export default client
