@@ -5,6 +5,8 @@ import { WebSocketLink } from 'apollo-link-ws';
5
5
import fetch from 'node-fetch' ;
6
6
import path from 'path' ;
7
7
import { debug } from './debug' ;
8
+ import { createNetworkStatusNotifier } from 'react-apollo-network-status' ;
9
+ import { NetworkStatus , UseApolloNetworkStatusOptions } from 'react-apollo-network-status/dist/src/useApolloNetworkStatus' ;
8
10
9
11
const moduleLog = debug . extend ( 'client' )
10
12
@@ -41,6 +43,7 @@ export interface IApolloClient<T> extends ApolloClient<T> {
41
43
jwt_token ?: string ;
42
44
path ?: string ;
43
45
ssl ?: boolean ;
46
+ useApolloNetworkStatus ?: ( options ?: UseApolloNetworkStatusOptions | undefined ) => NetworkStatus ;
44
47
}
45
48
46
49
const host = typeof ( window ) === 'object' ? window . location . host : '' ;
@@ -100,11 +103,13 @@ export function generateApolloClient(
100
103
// @ts -ignore
101
104
httpLink ,
102
105
) ;
106
+
107
+ const { link : notifierLink , useApolloNetworkStatus} = createNetworkStatusNotifier ( ) ;
103
108
104
109
const client : IApolloClient < any > = new ApolloClient ( {
105
110
ssrMode : true ,
106
111
// @ts -ignore
107
- link : concat ( authMiddleware , link ) ,
112
+ link : concat ( notifierLink , concat ( authMiddleware , link ) ) ,
108
113
connectToDevTools : true ,
109
114
cache : new InMemoryCache ( {
110
115
...forwardingArguments ?. InMemoryCache ,
@@ -130,6 +135,7 @@ export function generateApolloClient(
130
135
client . jwt_token = options . token ;
131
136
client . path = options . path ;
132
137
client . ssl = options . ssl ;
138
+ client . useApolloNetworkStatus = useApolloNetworkStatus ;
133
139
log ( { client } ) ;
134
140
135
141
return client ;
0 commit comments