Unverified Commit fbcc0e81 authored by Luis Alvarez D's avatar Luis Alvarez D Committed by GitHub

😌 (#9923)

parent 2f1b15c6
...@@ -4,7 +4,7 @@ import { ApolloProvider } from '@apollo/react-hooks' ...@@ -4,7 +4,7 @@ import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client' import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory' import { InMemoryCache } from 'apollo-cache-inmemory'
let apolloClient = null let globalApolloClient = null
/** /**
* Creates and provides the apolloContext * Creates and provides the apolloContext
...@@ -110,11 +110,11 @@ function initApolloClient(initialState) { ...@@ -110,11 +110,11 @@ function initApolloClient(initialState) {
} }
// Reuse client on the client-side // Reuse client on the client-side
if (!apolloClient) { if (!globalApolloClient) {
apolloClient = createApolloClient(initialState) globalApolloClient = createApolloClient(initialState)
} }
return apolloClient return globalApolloClient
} }
/** /**
......
...@@ -6,7 +6,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory' ...@@ -6,7 +6,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http' import { HttpLink } from 'apollo-link-http'
import fetch from 'isomorphic-unfetch' import fetch from 'isomorphic-unfetch'
let apolloClient = null let globalApolloClient = null
/** /**
* Creates and provides the apolloContext * Creates and provides the apolloContext
...@@ -112,11 +112,11 @@ function initApolloClient(initialState) { ...@@ -112,11 +112,11 @@ function initApolloClient(initialState) {
} }
// Reuse client on the client-side // Reuse client on the client-side
if (!apolloClient) { if (!globalApolloClient) {
apolloClient = createApolloClient(initialState) globalApolloClient = createApolloClient(initialState)
} }
return apolloClient return globalApolloClient
} }
/** /**
......
...@@ -44,7 +44,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) { ...@@ -44,7 +44,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
// Initialize ApolloClient, add it to the ctx object so // Initialize ApolloClient, add it to the ctx object so
// we can use it in `PageComponent.getInitialProp`. // we can use it in `PageComponent.getInitialProp`.
globalApolloClient = ctx.apolloClient = initApolloClient() const apolloClient = (ctx.apolloClient = initApolloClient())
// Run wrapped getInitialProps methods // Run wrapped getInitialProps methods
let pageProps = {} let pageProps = {}
...@@ -69,7 +69,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) { ...@@ -69,7 +69,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
<AppTree <AppTree
pageProps={{ pageProps={{
...pageProps, ...pageProps,
globalApolloClient, apolloClient,
}} }}
/> />
) )
...@@ -87,7 +87,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) { ...@@ -87,7 +87,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
} }
// Extract query data from the Apollo store // Extract query data from the Apollo store
const apolloState = globalApolloClient.cache.extract() const apolloState = apolloClient.cache.extract()
return { return {
...pageProps, ...pageProps,
......
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