Unverified Commit 026785d5 authored by Jack Clackett's avatar Jack Clackett Committed by GitHub

Update with-apollo examples to merge existing cache (#15804)

parent 8703f134
...@@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) { ...@@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) {
// If your page has Next.js data fetching methods that use Apollo Client, the initial state // If your page has Next.js data fetching methods that use Apollo Client, the initial state
// get hydrated here // get hydrated here
if (initialState) { if (initialState) {
_apolloClient.cache.restore(initialState) // Get existing cache, loaded during client side data fetching
const existingCache = _apolloClient.extract()
// Restore the cache using the data passed from getStaticProps/getServerSideProps
// combined with the existing cached data
_apolloClient.cache.restore({ ...existingCache, ...initialState })
} }
// For SSG and SSR always create a new Apollo Client // For SSG and SSR always create a new Apollo Client
if (typeof window === 'undefined') return _apolloClient if (typeof window === 'undefined') return _apolloClient
......
...@@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) { ...@@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) {
// If your page has Next.js data fetching methods that use Apollo Client, the initial state // If your page has Next.js data fetching methods that use Apollo Client, the initial state
// gets hydrated here // gets hydrated here
if (initialState) { if (initialState) {
_apolloClient.cache.restore(initialState) // Get existing cache, loaded during client side data fetching
const existingCache = _apolloClient.extract()
// Restore the cache using the data passed from getStaticProps/getServerSideProps
// combined with the existing cached data
_apolloClient.cache.restore({ ...existingCache, ...initialState })
} }
// For SSG and SSR always create a new Apollo Client // For SSG and SSR always create a new Apollo Client
if (typeof window === 'undefined') return _apolloClient if (typeof window === 'undefined') return _apolloClient
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment