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