提交 d166840e 编写于 作者: B Bee Ellis 提交者: Tim Neutkens

Fix shadowing of apolloClient (#9917)

* Remove redefinition of apolloClient

It seems that the definition of `apolloClient` on line 47 seems to be a intended to be defining the `apolloClient` defined in global scope. That re-declaration of the `apolloClient` variable is removed in favor of assigning the return of `initApolloClient()` to the globally defined `apolloClient`

* Rename the global apollo client to globalApolloClient
上级 2a70b268
......@@ -6,7 +6,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'
import fetch from 'isomorphic-unfetch'
let apolloClient = null
let globalApolloClient = null
/**
* Creates and provides the apolloContext
......@@ -44,7 +44,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
// Initialize ApolloClient, add it to the ctx object so
// we can use it in `PageComponent.getInitialProp`.
const apolloClient = (ctx.apolloClient = initApolloClient())
globalApolloClient = ctx.apolloClient = initApolloClient()
// Run wrapped getInitialProps methods
let pageProps = {}
......@@ -69,7 +69,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
<AppTree
pageProps={{
...pageProps,
apolloClient,
globalApolloClient,
}}
/>
)
......@@ -87,7 +87,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
}
// Extract query data from the Apollo store
const apolloState = apolloClient.cache.extract()
const apolloState = globalApolloClient.cache.extract()
return {
...pageProps,
......@@ -112,11 +112,11 @@ function initApolloClient(initialState) {
}
// Reuse client on the client-side
if (!apolloClient) {
apolloClient = createApolloClient(initialState)
if (!globalApolloClient) {
globalApolloClient = createApolloClient(initialState)
}
return apolloClient
return globalApolloClient
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册