Skip to content

Commit c3c57dd

Browse files
committed
fix(TestOperation): ensure operation-definition is fetched in runtime
1 parent 8e25401 commit c3c57dd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/apollo-angular/testing/src/operation.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ExecutionResult, GraphQLError, Kind, OperationTypeNode } from 'graphql';
2-
import type { FragmentDefinitionNode, OperationDefinitionNode } from 'graphql/index';
32
import { Observer } from 'rxjs';
43
import { ApolloError, FetchResult, Operation as LinkOperation } from '@apollo/client/core';
54
import { getMainDefinition } from '@apollo/client/utilities';
@@ -13,13 +12,10 @@ export type Operation = LinkOperation & {
1312
};
1413

1514
export class TestOperation<T = { [key: string]: any }> {
16-
private readonly definition: OperationDefinitionNode | FragmentDefinitionNode;
17-
1815
constructor(
1916
public readonly operation: Operation,
2017
private readonly observer: Observer<FetchResult<T>>,
2118
) {
22-
this.definition = getMainDefinition(this.operation.query);
2319
}
2420

2521
public flush(result: ExecutionResult<T> | ApolloError): void {
@@ -28,10 +24,12 @@ export class TestOperation<T = { [key: string]: any }> {
2824
} else {
2925
const fetchResult = result ? { ...result } : result;
3026
this.observer.next(fetchResult);
27+
28+
const definition = getMainDefinition(this.operation.query);
3129

3230
if (
33-
this.definition.kind === Kind.OPERATION_DEFINITION &&
34-
this.definition.operation !== OperationTypeNode.SUBSCRIPTION
31+
definition.kind === Kind.OPERATION_DEFINITION &&
32+
definition.operation !== OperationTypeNode.SUBSCRIPTION
3533
) {
3634
this.complete();
3735
}

0 commit comments

Comments
 (0)