未验证 提交 fbcc0e81 编写于 作者: L Luis Alvarez D 提交者: GitHub

😌 (#9923)

上级 2f1b15c6
......@@ -4,7 +4,7 @@ import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
let apolloClient = null
let globalApolloClient = null
/**
* Creates and provides the apolloContext
......@@ -110,11 +110,11 @@ function initApolloClient(initialState) {
}
// Reuse client on the client-side
if (!apolloClient) {
apolloClient = createApolloClient(initialState)
if (!globalApolloClient) {
globalApolloClient = createApolloClient(initialState)
}
return apolloClient
return globalApolloClient
}
/**
......
......@@ -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
......@@ -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
}
/**
......
......@@ -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`.
globalApolloClient = ctx.apolloClient = initApolloClient()
const apolloClient = (ctx.apolloClient = initApolloClient())
// Run wrapped getInitialProps methods
let pageProps = {}
......@@ -69,7 +69,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
<AppTree
pageProps={{
...pageProps,
globalApolloClient,
apolloClient,
}}
/>
)
......@@ -87,7 +87,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
}
// Extract query data from the Apollo store
const apolloState = globalApolloClient.cache.extract()
const apolloState = apolloClient.cache.extract()
return {
...pageProps,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册