Interesting video from the CodePen podcast in which Shaw goes over this approach to SSR with Next and Apollo:
A probably-better approach is to use the
getDataFromTree
method, which walks down the tree and executes the queries to fill up the ApolloClient cache.
- Create a shared
ApolloClient
instance- Render the page using
getDataFromTree()
to fill the cache with data- Render the page again with that data using Next’s
Document.getInitialProps()
- Extract the cache to deliver with the page and hydrate the client-side Apollo cache
Nice!
CodePen Podcast #331: Next.js + Apollo + Server Side Rendering (SSR) →
Example Repository →