Skip to content

Instantly share code, notes, and snippets.

@kluu1
Last active March 24, 2020 01:22
Show Gist options
  • Select an option

  • Save kluu1/eb4bec7ec61810d9d04a78a42da96714 to your computer and use it in GitHub Desktop.

Select an option

Save kluu1/eb4bec7ec61810d9d04a78a42da96714 to your computer and use it in GitHub Desktop.
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import withApollo from 'next-with-apollo'
import { createHttpLink } from 'apollo-link-http'
import fetch from 'isomorphic-unfetch'
const GRAPHQL_URL = '/api/graphql'
const link = createHttpLink({
fetch, // Switches between unfetch & node-fetch for client & server.
uri: GRAPHQL_URL
})
export default withApollo(
// You can get headers and ctx (context) from the callback params
// e.g. ({ headers, ctx, initialState })
({ initialState }) =>
new ApolloClient({
link,
cache: new InMemoryCache()
// rehydrate the cache using the initial data passed from the server:
.restore(initialState || {})
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment