/**
 * 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 { onError } from 'apollo-link-error'
import { createUploadLink } from 'apollo-upload-client'
import { ApolloClient, InMemoryCache, from } from '@apollo/client'
import fetch from 'isomorphic-unfetch'

const client = new ApolloClient({
  link: from([
    onError((errors) => {
      console.log(errors)
    }),
    createUploadLink({
      uri: '/graphql/',
      credentials: 'include',
      fetch,
    }) as any,
  ]),
  cache: new InMemoryCache(),
})

export default client
