123456789101112131415161718192021222324252627282930313233 |
- /**
- * 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, { InMemoryCache } from 'apollo-boost'
- import { endpoint, prodEndpoint } from '../config'
- function createClient({ ctx, headers, initialState }) {
- return new ApolloClient({
- uri: process.env.NODE_ENV === 'development' ? endpoint : prodEndpoint,
- cache: new InMemoryCache().restore(initialState || {}),
- request: operation => {
- operation.setContext({
- fetchOptions: {
- credentials: 'include'
- },
- headers
- })
- },
- clientState: {
- resolvers: {},
- defaults: {}
- }
- })
- }
- export default withApollo(createClient)
|