@@ -252,19 +252,17 @@ export class ObservableQuery<
252
252
query : TypedDocumentNode < TData , TVariables > ;
253
253
variables : TVariables ;
254
254
} ;
255
- private input : Subject <
255
+ private input ! : Subject <
256
256
QueryNotification . Value < TData > & {
257
257
query : DocumentNode | TypedDocumentNode < TData , TVariables > ;
258
258
variables : TVariables ;
259
259
meta : Meta ;
260
260
}
261
261
> ;
262
- private subject : BehaviorSubject <
262
+ private subject ! : BehaviorSubject <
263
263
SubjectValue < MaybeMasked < TData > , TVariables >
264
264
> ;
265
- private readonly observable : Observable <
266
- ApolloQueryResult < MaybeMasked < TData > >
267
- > ;
265
+ private observable ! : Observable < ApolloQueryResult < MaybeMasked < TData > > > ;
268
266
269
267
private isTornDown : boolean ;
270
268
private queryManager : QueryManager ;
@@ -339,6 +337,13 @@ export class ObservableQuery<
339
337
variables : this . getVariablesWithDefaults ( options . variables ) ,
340
338
} ;
341
339
340
+ this . initializeObservablesQueue ( ) ;
341
+
342
+ const opDef = getOperationDefinition ( this . query ) ;
343
+ this . queryName = opDef && opDef . name && opDef . name . value ;
344
+ }
345
+
346
+ private initializeObservablesQueue ( ) {
342
347
this . subject = new BehaviorSubject <
343
348
SubjectValue < MaybeMasked < TData > , TVariables >
344
349
> ( {
@@ -438,26 +443,23 @@ export class ObservableQuery<
438
443
// be able to close `this.input`
439
444
this . input . complete = ( ) => { } ;
440
445
this . input . pipe ( this . operator ) . subscribe ( this . subject ) ;
441
-
442
- const opDef = getOperationDefinition ( this . query ) ;
443
- this . queryName = opDef && opDef . name && opDef . name . value ;
444
446
}
445
447
446
448
// We can't use Observable['subscribe'] here as the type as it conflicts with
447
449
// the ability to infer T from Subscribable<T>. This limits the surface area
448
450
// to the non-deprecated signature which works properly with type inference.
449
- public subscribe : (
451
+ public subscribe ! : (
450
452
observer :
451
453
| Partial < Observer < ApolloQueryResult < MaybeMasked < TData > > > >
452
454
| ( ( value : ApolloQueryResult < MaybeMasked < TData > > ) => void )
453
455
) => Subscription ;
454
456
455
- public pipe : Observable < ApolloQueryResult < MaybeMasked < TData > > > [ "pipe" ] ;
457
+ public pipe ! : Observable < ApolloQueryResult < MaybeMasked < TData > > > [ "pipe" ] ;
456
458
457
459
public [ Symbol . observable ] ! : ( ) => Subscribable <
458
460
ApolloQueryResult < MaybeMasked < TData > >
459
461
> ;
460
- public [ "@@observable" ] : ( ) => Subscribable <
462
+ public [ "@@observable" ] ! : ( ) => Subscribable <
461
463
ApolloQueryResult < MaybeMasked < TData > >
462
464
> ;
463
465
@@ -1435,6 +1437,16 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
1435
1437
return this . subject . observed ;
1436
1438
}
1437
1439
1440
+ /**
1441
+ * @internal
1442
+ * Tears down the `ObservableQuery` and stops all active operations by sending a `complete` notification.
1443
+ */
1444
+ public stop ( ) {
1445
+ this . subject . complete ( ) ;
1446
+ this . initializeObservablesQueue ( ) ;
1447
+ this . tearDownQuery ( ) ;
1448
+ }
1449
+
1438
1450
private tearDownQuery ( ) {
1439
1451
if ( this . isTornDown ) return ;
1440
1452
0 commit comments