1
1
import { ExecutionResult , GraphQLError , Kind , OperationTypeNode } from 'graphql' ;
2
- import type { FragmentDefinitionNode , OperationDefinitionNode } from 'graphql/index' ;
3
2
import { Observer } from 'rxjs' ;
4
3
import { ApolloError , FetchResult , Operation as LinkOperation } from '@apollo/client/core' ;
5
4
import { getMainDefinition } from '@apollo/client/utilities' ;
@@ -13,13 +12,10 @@ export type Operation = LinkOperation & {
13
12
} ;
14
13
15
14
export class TestOperation < T = { [ key : string ] : any } > {
16
- private readonly definition : OperationDefinitionNode | FragmentDefinitionNode ;
17
-
18
15
constructor (
19
16
public readonly operation : Operation ,
20
17
private readonly observer : Observer < FetchResult < T > > ,
21
18
) {
22
- this . definition = getMainDefinition ( this . operation . query ) ;
23
19
}
24
20
25
21
public flush ( result : ExecutionResult < T > | ApolloError ) : void {
@@ -28,10 +24,12 @@ export class TestOperation<T = { [key: string]: any }> {
28
24
} else {
29
25
const fetchResult = result ? { ...result } : result ;
30
26
this . observer . next ( fetchResult ) ;
27
+
28
+ const definition = getMainDefinition ( this . operation . query ) ;
31
29
32
30
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
35
33
) {
36
34
this . complete ( ) ;
37
35
}
0 commit comments