@@ -2,7 +2,7 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
2
2
import { expectTypeOf } from "expect-type" ;
3
3
import { Kind } from "graphql" ;
4
4
import { gql } from "graphql-tag" ;
5
- import { Observable , of } from "rxjs" ;
5
+ import { delay , Observable , of } from "rxjs" ;
6
6
7
7
import type {
8
8
ApolloQueryResult ,
@@ -1163,7 +1163,7 @@ describe("ApolloClient", () => {
1163
1163
} ,
1164
1164
} ;
1165
1165
const link = new ApolloLink ( ( ) => {
1166
- return of ( { data } ) ;
1166
+ return of ( { data } ) . pipe ( delay ( 20 ) ) ;
1167
1167
} ) ;
1168
1168
function newClient ( ) {
1169
1169
return new ApolloClient ( {
@@ -1216,6 +1216,13 @@ describe("ApolloClient", () => {
1216
1216
const observable = client . watchQuery < Data > ( { query } ) ;
1217
1217
const stream = new ObservableStream ( observable ) ;
1218
1218
1219
+ await expect ( stream ) . toEmitTypedValue ( {
1220
+ data : undefined ,
1221
+ loading : true ,
1222
+ networkStatus : NetworkStatus . loading ,
1223
+ partial : true ,
1224
+ } ) ;
1225
+
1219
1226
await expect ( stream ) . toEmitTypedValue ( {
1220
1227
data,
1221
1228
loading : false ,
@@ -1265,6 +1272,13 @@ describe("ApolloClient", () => {
1265
1272
const observable = client . watchQuery < Data > ( { query } ) ;
1266
1273
const stream = new ObservableStream ( observable ) ;
1267
1274
1275
+ await expect ( stream ) . toEmitTypedValue ( {
1276
+ data : undefined ,
1277
+ loading : true ,
1278
+ networkStatus : NetworkStatus . loading ,
1279
+ partial : true ,
1280
+ } ) ;
1281
+
1268
1282
await expect ( stream ) . toEmitTypedValue ( {
1269
1283
data,
1270
1284
loading : false ,
@@ -1321,6 +1335,13 @@ describe("ApolloClient", () => {
1321
1335
const observable = client . watchQuery < Data > ( { query } ) ;
1322
1336
const stream = new ObservableStream ( observable ) ;
1323
1337
1338
+ await expect ( stream ) . toEmitTypedValue ( {
1339
+ data : undefined ,
1340
+ loading : true ,
1341
+ networkStatus : NetworkStatus . loading ,
1342
+ partial : true ,
1343
+ } ) ;
1344
+
1324
1345
{
1325
1346
const result = await stream . takeNext ( ) ;
1326
1347
@@ -1359,6 +1380,13 @@ describe("ApolloClient", () => {
1359
1380
const observable = client . watchQuery < Data > ( { query } ) ;
1360
1381
const stream = new ObservableStream ( observable ) ;
1361
1382
1383
+ await expect ( stream ) . toEmitTypedValue ( {
1384
+ data : undefined ,
1385
+ loading : true ,
1386
+ networkStatus : NetworkStatus . loading ,
1387
+ partial : true ,
1388
+ } ) ;
1389
+
1362
1390
{
1363
1391
const result = await stream . takeNext ( ) ;
1364
1392
@@ -2125,7 +2153,6 @@ describe("ApolloClient", () => {
2125
2153
const observable = client . watchQuery ( {
2126
2154
query,
2127
2155
fetchPolicy,
2128
- notifyOnNetworkStatusChange : true ,
2129
2156
} ) ;
2130
2157
const stream = new ObservableStream ( observable ) ;
2131
2158
await expect ( stream ) . toEmitTypedValue ( {
@@ -2158,12 +2185,16 @@ describe("ApolloClient", () => {
2158
2185
} ) ;
2159
2186
client . prioritizeCacheValues = true ;
2160
2187
2161
- const observable = client . watchQuery ( {
2162
- query,
2163
- fetchPolicy,
2164
- notifyOnNetworkStatusChange : true ,
2165
- } ) ;
2188
+ const observable = client . watchQuery ( { query, fetchPolicy } ) ;
2166
2189
const stream = new ObservableStream ( observable ) ;
2190
+
2191
+ await expect ( stream ) . toEmitTypedValue ( {
2192
+ data : undefined ,
2193
+ loading : true ,
2194
+ networkStatus : NetworkStatus . loading ,
2195
+ partial : true ,
2196
+ } ) ;
2197
+
2167
2198
await expect ( stream ) . toEmitTypedValue ( {
2168
2199
loading : false ,
2169
2200
networkStatus : NetworkStatus . ready ,
@@ -2197,8 +2228,7 @@ describe("ApolloClient", () => {
2197
2228
notifyOnNetworkStatusChange : true ,
2198
2229
} ) ;
2199
2230
const stream = new ObservableStream ( observable ) ;
2200
- // not really part of this test case but I decided to leave it here to highlight this
2201
- // in the case of a network request, `no-cache` emits a `loading` state while `network-only` etc. do not?
2231
+
2202
2232
await expect ( stream ) . toEmitTypedValue ( {
2203
2233
loading : true ,
2204
2234
networkStatus : NetworkStatus . loading ,
@@ -2957,7 +2987,19 @@ describe("ApolloClient", () => {
2957
2987
const stream = new ObservableStream ( observable ) ;
2958
2988
link . simulateResult ( { result : { data : { foo : { bar : 1 } } } } , true ) ;
2959
2989
2960
- await stream . takeNext ( ) ;
2990
+ await expect ( stream ) . toEmitTypedValue ( {
2991
+ data : undefined ,
2992
+ loading : true ,
2993
+ networkStatus : NetworkStatus . loading ,
2994
+ partial : true ,
2995
+ } ) ;
2996
+
2997
+ await expect ( stream ) . toEmitTypedValue ( {
2998
+ data : { foo : { bar : 1 } } ,
2999
+ loading : false ,
3000
+ networkStatus : NetworkStatus . ready ,
3001
+ partial : false ,
3002
+ } ) ;
2961
3003
2962
3004
const result = client . refetchQueries ( {
2963
3005
include : "all" ,
0 commit comments