withApollo.js 762 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Using next-with-apollo
  3. * https://github.com/lfades/next-with-apollo
  4. *
  5. * Changes:
  6. * * Reading endpoint and prodEndpoint from a config file
  7. * * Setting request to handle credentials.
  8. */
  9. import withApollo from 'next-with-apollo'
  10. import ApolloClient from 'apollo-boost'
  11. import { endpoint, prodEndpoint } from '../config'
  12. function createClient ({ ctx, headers, initialState }) {
  13. return new ApolloClient({
  14. uri: process.env.NODE_ENV === 'development' ? endpoint : prodEndpoint,
  15. request: operation => {
  16. operation.setContext({
  17. fetchOptions: {
  18. credentials: 'include'
  19. },
  20. headers
  21. })
  22. },
  23. clientState: {
  24. resolvers: {},
  25. defaults: {}
  26. }
  27. })
  28. }
  29. export default withApollo(createClient)