Last active
March 24, 2020 01:22
-
-
Save kluu1/eb4bec7ec61810d9d04a78a42da96714 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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