@@ -38,6 +38,7 @@ const getServerClient = (
38
38
opts : Partial < ApolloClientOptions < any > > ,
39
39
cacheOpts ?: ApolloReducerConfig ,
40
40
initialData ?: any ,
41
+ linkState ?: any ,
41
42
) => {
42
43
let link : ApolloLink = new HttpLink ( {
43
44
uri,
@@ -61,6 +62,10 @@ const getServerClient = (
61
62
cache . restore ( initialData ) ;
62
63
}
63
64
65
+ if ( linkState ) {
66
+ link = ApolloLink . from ( [ link , linkState ] ) ;
67
+ }
68
+
64
69
return new ApolloClient ( {
65
70
link,
66
71
cache,
@@ -75,10 +80,11 @@ const getClient = (
75
80
opts : Partial < ApolloClientOptions < any > > ,
76
81
cacheOpts ?: ApolloReducerConfig ,
77
82
initialData ?: any ,
83
+ linkState ?: any ,
78
84
) => {
79
85
if ( ! ( process as any ) . browser ) {
80
86
// on server, create a new client for each request
81
- return getServerClient ( uri , cookies , opts , cacheOpts , initialData ) ;
87
+ return getServerClient ( uri , cookies , opts , cacheOpts , initialData , linkState ) ;
82
88
}
83
89
// on client, create singleton
84
90
if ( ! client ) {
@@ -91,11 +97,12 @@ export type Options = {
91
97
url : string ;
92
98
opts ?: ApolloReducerConfig ;
93
99
apolloOpts ?: Partial < ApolloClientOptions < any > > ;
100
+ linkState ?: any ;
94
101
} ;
95
102
96
103
type Props = { initialData ?: any ; childProps ?: any } ;
97
104
98
- export default ( { url, opts, apolloOpts } : Options ) => {
105
+ export default ( { url, opts, apolloOpts, linkState } : Options ) => {
99
106
// tslint:disable-next-line variable-name
100
107
return ( Component : React . ComponentType < any > & { getInitialProps ?: ( ctx : any ) => Promise < any > } ) =>
101
108
class extends React . Component < Props > {
@@ -109,7 +116,7 @@ export default ({ url, opts, apolloOpts }: Options) => {
109
116
110
117
public static async getInitialProps ( ctx : any ) : Promise < { initialData : any ; childProps : any } > {
111
118
const cookies = ctx . req && ctx . req . cookies ;
112
- const client = getClient ( url , cookies , apolloOpts || { } , opts ) ;
119
+ const client = getClient ( url , cookies , apolloOpts , linkState || { } , opts ) ;
113
120
114
121
const childProps = Component . getInitialProps ? await Component . getInitialProps ( ctx ) : { } ;
115
122
0 commit comments