Created
November 21, 2019 19:54
-
-
Save michal-wrzosek/ce34cb7b886f2dd5af0e6b0452bdd3d9 to your computer and use it in GitHub Desktop.
Next.js + Apollo - withApollo
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 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