@@ -3,6 +3,7 @@ import Head from 'next/head'
3
3
import { ApolloProvider } from '@apollo/react-hooks'
4
4
import { ApolloClient , InMemoryCache , HttpLink } from 'apollo-boost'
5
5
import fetch from 'isomorphic-unfetch'
6
+ import { isFunction } from 'lodash'
6
7
7
8
let apolloClient = null
8
9
@@ -40,7 +41,11 @@ export default apolloConfig => {
40
41
41
42
// Initialize ApolloClient, add it to the ctx object so
42
43
// we can use it in `PageComponent.getInitialProp`.
43
- const apolloClient = ( ctx . apolloClient = initApolloClient ( apolloConfig , null ) )
44
+ const apolloClient = ( ctx . apolloClient = initApolloClient (
45
+ apolloConfig ,
46
+ null ,
47
+ ctx
48
+ ) )
44
49
45
50
// Run wrapped getInitialProps methods
46
51
let pageProps = { }
@@ -101,7 +106,10 @@ export default apolloConfig => {
101
106
* Creates or reuses apollo client in the browser.
102
107
* @param {Object } initialState
103
108
*/
104
- function initApolloClient ( apolloConfig , initialState = { } ) {
109
+ function initApolloClient ( apolloConfig , initialState = { } , ctx ) {
110
+ if ( isFunction ( apolloConfig ) ) {
111
+ apolloConfig = apolloConfig ( ctx )
112
+ }
105
113
// Make sure to create a new client for every server-side request so that data
106
114
// isn't shared between connections (which would be bad)
107
115
if ( typeof window === 'undefined' ) {
0 commit comments