forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathResolveInfo.ts
More file actions
131 lines (114 loc) · 3.73 KB
/
ResolveInfo.ts
File metadata and controls
131 lines (114 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import type { ObjMap } from '../jsutils/ObjMap.js';
import type { Path } from '../jsutils/Path.js';
import type {
FieldNode,
FragmentDefinitionNode,
OperationDefinitionNode,
} from '../language/ast.js';
import type {
GraphQLField,
GraphQLObjectType,
GraphQLOutputType,
GraphQLResolveInfo,
GraphQLSchema,
} from '../type/index.js';
import type { FieldDetailsList } from './collectFields.js';
import type { ValidatedExecutionArgs } from './execute.js';
import type { VariableValues } from './values.js';
/** @internal */
export class ResolveInfo implements GraphQLResolveInfo {
private _validatedExecutionArgs: ValidatedExecutionArgs;
private _fieldDef: GraphQLField<unknown, unknown>;
private _fieldDetailsList: FieldDetailsList;
private _parentType: GraphQLObjectType;
private _path: Path;
private _abortSignal: AbortSignal | undefined;
private _registerAbortSignal: () => {
abortSignal: AbortSignal | undefined;
unregister?: () => void;
};
private _unregisterAbortSignal: (() => void) | undefined;
private _fieldName: string | undefined;
private _fieldNodes: ReadonlyArray<FieldNode> | undefined;
private _returnType: GraphQLOutputType | undefined;
private _schema: GraphQLSchema | undefined;
private _fragments: ObjMap<FragmentDefinitionNode> | undefined;
private _rootValue: unknown;
private _rootValueDefined?: boolean;
private _operation: OperationDefinitionNode | undefined;
private _variableValues: VariableValues | undefined;
// eslint-disable-next-line max-params
constructor(
validatedExecutionArgs: ValidatedExecutionArgs,
fieldDef: GraphQLField<unknown, unknown>,
fieldDetailsList: FieldDetailsList,
parentType: GraphQLObjectType,
path: Path,
registerAbortSignal: () => {
abortSignal: AbortSignal | undefined;
unregister?: () => void;
},
) {
this._validatedExecutionArgs = validatedExecutionArgs;
this._fieldDef = fieldDef;
this._fieldDetailsList = fieldDetailsList;
this._parentType = parentType;
this._path = path;
this._registerAbortSignal = registerAbortSignal;
}
get fieldName(): string {
this._fieldName ??= this._fieldDef.name;
return this._fieldName;
}
get fieldNodes(): ReadonlyArray<FieldNode> {
this._fieldNodes ??= this._fieldDetailsList.map(
(fieldDetails) => fieldDetails.node,
);
return this._fieldNodes;
}
get returnType(): GraphQLOutputType {
this._returnType ??= this._fieldDef.type;
return this._returnType;
}
get parentType(): GraphQLObjectType {
return this._parentType;
}
get path(): Path {
return this._path;
}
get schema(): GraphQLSchema {
this._schema ??= this._validatedExecutionArgs.schema;
return this._schema;
}
get fragments(): ObjMap<FragmentDefinitionNode> {
this._fragments ??= this._validatedExecutionArgs.fragmentDefinitions;
return this._fragments;
}
get rootValue(): unknown {
if (!this._rootValueDefined) {
this._rootValueDefined = true;
this._rootValue = this._validatedExecutionArgs.rootValue;
}
return this._rootValue;
}
get operation(): OperationDefinitionNode {
this._operation ??= this._validatedExecutionArgs.operation;
return this._operation;
}
get variableValues(): VariableValues {
this._variableValues ??= this._validatedExecutionArgs.variableValues;
return this._variableValues;
}
get abortSignal(): AbortSignal | undefined {
if (this._abortSignal !== undefined) {
return this._abortSignal;
}
const { abortSignal, unregister } = this._registerAbortSignal();
this._abortSignal = abortSignal;
this._unregisterAbortSignal = unregister;
return this._abortSignal;
}
unregisterAbortSignal(): void {
this._unregisterAbortSignal?.();
}
}