import ApolloClient from 'apollo-boost' ; import withApollo from 'next-with-apollo' ; export default withApollo ( ( { headers } ) => { let uri ; if ( headers && process . env . apiEndpoint && process . env . apiEndpoint . startsWith ( '/' ) ) { uri = `https://${ headers . host }${ process . env . apiEndpoint }` ; } else { uri = process . env . apiEndpoint ; } return new ApolloClient ( { uri , request : async ( operation ) => { operation . setContext ( { fetchOptions : { credentials : 'include' } , headers , } ) ; } , } ) ; } ) ;