Skip to content

Commit fbcc0e8

Browse files
author
Luis Alvarez D
authored
😌 (#9923)
1 parent 2f1b15c commit fbcc0e8

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

‎examples/api-routes-apollo-server-and-client/apollo/client.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApolloProvider } from '@apollo/react-hooks'
44
import { ApolloClient } from 'apollo-client'
55
import { InMemoryCache } from 'apollo-cache-inmemory'
66

7-
let apolloClient = null
7+
let globalApolloClient = null
88

99
/**
1010
* Creates and provides the apolloContext
@@ -110,11 +110,11 @@ function initApolloClient(initialState) {
110110
}
111111

112112
// Reuse client on the client-side
113-
if (!apolloClient) {
114-
apolloClient = createApolloClient(initialState)
113+
if (!globalApolloClient) {
114+
globalApolloClient = createApolloClient(initialState)
115115
}
116116

117-
return apolloClient
117+
return globalApolloClient
118118
}
119119

120120
/**

‎examples/with-apollo-and-redux/lib/apollo.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
66
import { HttpLink } from 'apollo-link-http'
77
import fetch from 'isomorphic-unfetch'
88

9-
let apolloClient = null
9+
let globalApolloClient = null
1010

1111
/**
1212
* Creates and provides the apolloContext
@@ -112,11 +112,11 @@ function initApolloClient(initialState) {
112112
}
113113

114114
// Reuse client on the client-side
115-
if (!apolloClient) {
116-
apolloClient = createApolloClient(initialState)
115+
if (!globalApolloClient) {
116+
globalApolloClient = createApolloClient(initialState)
117117
}
118118

119-
return apolloClient
119+
return globalApolloClient
120120
}
121121

122122
/**

‎examples/with-apollo/lib/apollo.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
4444

4545
// Initialize ApolloClient, add it to the ctx object so
4646
// we can use it in `PageComponent.getInitialProp`.
47-
globalApolloClient = ctx.apolloClient = initApolloClient()
47+
const apolloClient = (ctx.apolloClient = initApolloClient())
4848

4949
// Run wrapped getInitialProps methods
5050
let pageProps = {}
@@ -69,7 +69,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
6969
<AppTree
7070
pageProps={{
7171
...pageProps,
72-
globalApolloClient,
72+
apolloClient,
7373
}}
7474
/>
7575
)
@@ -87,7 +87,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
8787
}
8888

8989
// Extract query data from the Apollo store
90-
const apolloState = globalApolloClient.cache.extract()
90+
const apolloState = apolloClient.cache.extract()
9191

9292
return {
9393
...pageProps,

0 commit comments

Comments
 (0)