Skip to content

Instantly share code, notes, and snippets.

@michal-wrzosek
Created November 21, 2019 19:54
Show Gist options
  • Save michal-wrzosek/ce34cb7b886f2dd5af0e6b0452bdd3d9 to your computer and use it in GitHub Desktop.
Save michal-wrzosek/ce34cb7b886f2dd5af0e6b0452bdd3d9 to your computer and use it in GitHub Desktop.
Next.js + Apollo - withApollo
import withApollo from 'next-with-apollo';
import ApolloClient, { InMemoryCache } from 'apollo-boost';
export default (uri: string) =>
withApollo(
props =>
new ApolloClient({
uri,
cache: new InMemoryCache().restore(props.initialState || {}),
credentials: 'include',
...(props.ctx && props.ctx.req
? {
headers: {
cookie: props.ctx.req.headers['cookie'],
},
}
: {}),
}),
{ getDataFromTree: 'ssr' },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment