@graphitation/supermassive 2.5.0 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/CHANGELOG.md +18 -2
- package/lib/benchmarks/index.js +2 -2
- package/lib/benchmarks/index.js.map +2 -2
- package/lib/benchmarks/index.mjs +2 -2
- package/lib/benchmarks/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/index.d.ts +4 -2
- package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/index.js +8 -2
- package/lib/benchmarks/swapi-schema/index.js.map +2 -2
- package/lib/benchmarks/swapi-schema/index.mjs +8 -2
- package/lib/benchmarks/swapi-schema/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts.map +1 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js +916 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js.map +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs +903 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs.map +7 -0
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +53 -17
- package/lib/benchmarks/swapi-schema/resolvers.js.map +2 -2
- package/lib/benchmarks/swapi-schema/resolvers.mjs +54 -18
- package/lib/benchmarks/swapi-schema/resolvers.mjs.map +2 -2
- package/lib/collectFields.d.ts +28 -6
- package/lib/collectFields.d.ts.map +1 -1
- package/lib/collectFields.js +155 -28
- package/lib/collectFields.js.map +3 -3
- package/lib/collectFields.mjs +150 -29
- package/lib/collectFields.mjs.map +2 -2
- package/lib/definition.js +1 -1
- package/lib/definition.js.map +2 -2
- package/lib/definition.mjs +1 -1
- package/lib/definition.mjs.map +2 -2
- package/lib/directives.d.ts +2 -73
- package/lib/directives.d.ts.map +1 -1
- package/lib/directives.js +10 -123
- package/lib/directives.js.map +2 -2
- package/lib/directives.mjs +13 -122
- package/lib/directives.mjs.map +2 -2
- package/lib/executeWithoutSchema.d.ts +50 -13
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +1038 -184
- package/lib/executeWithoutSchema.js.map +3 -3
- package/lib/executeWithoutSchema.mjs +1049 -186
- package/lib/executeWithoutSchema.mjs.map +3 -3
- package/lib/extractImplicitTypesRuntime.js +2 -2
- package/lib/extractImplicitTypesRuntime.js.map +2 -2
- package/lib/extractImplicitTypesRuntime.mjs +2 -2
- package/lib/extractImplicitTypesRuntime.mjs.map +2 -2
- package/lib/hooks/types.d.ts +1 -1
- package/lib/hooks/types.d.ts.map +1 -1
- package/lib/index.d.ts +4 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +2 -2
- package/lib/index.mjs +4 -1
- package/lib/index.mjs.map +2 -2
- package/lib/jsutils/AccumulatorMap.d.ts +8 -0
- package/lib/jsutils/AccumulatorMap.d.ts.map +1 -0
- package/lib/jsutils/AccumulatorMap.js +36 -0
- package/lib/jsutils/AccumulatorMap.js.map +7 -0
- package/lib/jsutils/AccumulatorMap.mjs +17 -0
- package/lib/jsutils/AccumulatorMap.mjs.map +7 -0
- package/lib/jsutils/Maybe.d.ts +1 -1
- package/lib/jsutils/Maybe.d.ts.map +1 -1
- package/lib/jsutils/ObjMap.d.ts +2 -2
- package/lib/jsutils/ObjMap.d.ts.map +1 -1
- package/lib/jsutils/PromiseOrValue.d.ts +1 -1
- package/lib/jsutils/PromiseOrValue.d.ts.map +1 -1
- package/lib/jsutils/didYouMean.d.ts +1 -2
- package/lib/jsutils/didYouMean.d.ts.map +1 -1
- package/lib/jsutils/didYouMean.js.map +2 -2
- package/lib/jsutils/didYouMean.mjs.map +2 -2
- package/lib/jsutils/instanceOf.js.map +2 -2
- package/lib/jsutils/instanceOf.mjs.map +2 -2
- package/lib/subscribeWithSchema.d.ts +3 -2
- package/lib/subscribeWithSchema.d.ts.map +1 -1
- package/lib/subscribeWithSchema.js.map +2 -2
- package/lib/subscribeWithSchema.mjs.map +2 -2
- package/lib/subscribeWithoutSchema.d.ts +3 -35
- package/lib/subscribeWithoutSchema.d.ts.map +1 -1
- package/lib/subscribeWithoutSchema.js +1 -163
- package/lib/subscribeWithoutSchema.js.map +2 -2
- package/lib/subscribeWithoutSchema.mjs +2 -175
- package/lib/subscribeWithoutSchema.mjs.map +2 -2
- package/lib/supermassive-ast/TypedAST.d.ts +370 -0
- package/lib/supermassive-ast/TypedAST.d.ts.map +1 -0
- package/lib/supermassive-ast/TypedAST.js +29 -0
- package/lib/supermassive-ast/TypedAST.js.map +7 -0
- package/lib/supermassive-ast/TypedAST.mjs +10 -0
- package/lib/supermassive-ast/TypedAST.mjs.map +7 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.d.ts +56 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.d.ts.map +1 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.js +473 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.js.map +7 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.mjs +463 -0
- package/lib/supermassive-ast/addTypesToRequestDocument.mjs.map +7 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.d.ts +3 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.d.ts.map +1 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.js +34 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.js.map +7 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.mjs +17 -0
- package/lib/supermassive-ast/annotateDocumentGraphQLTransform.mjs.map +7 -0
- package/lib/supermassive-ast/directives.d.ts +36 -0
- package/lib/supermassive-ast/directives.d.ts.map +1 -0
- package/lib/supermassive-ast/directives.js +165 -0
- package/lib/supermassive-ast/directives.js.map +7 -0
- package/lib/supermassive-ast/directives.mjs +153 -0
- package/lib/supermassive-ast/directives.mjs.map +7 -0
- package/lib/supermassive-ast/index.d.ts +6 -0
- package/lib/supermassive-ast/index.d.ts.map +1 -0
- package/lib/supermassive-ast/index.js +37 -0
- package/lib/supermassive-ast/index.js.map +7 -0
- package/lib/supermassive-ast/index.mjs +27 -0
- package/lib/supermassive-ast/index.mjs.map +7 -0
- package/lib/types.d.ts +80 -24
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +14 -0
- package/lib/types.js.map +2 -2
- package/lib/types.mjs +11 -0
- package/lib/types.mjs.map +3 -3
- package/lib/utilities/mergeResolvers.d.ts +1 -1
- package/lib/utilities/mergeResolvers.d.ts.map +1 -1
- package/lib/utilities/mergeResolvers.js.map +2 -2
- package/lib/utilities/mergeResolvers.mjs.map +2 -2
- package/lib/utilities/typeNameFromAST.d.ts +1 -1
- package/lib/utilities/typeNameFromAST.d.ts.map +1 -1
- package/lib/utilities/typeNameFromAST.js.map +1 -1
- package/lib/utilities/typeNameFromAST.mjs.map +1 -1
- package/lib/values.d.ts +3 -4
- package/lib/values.d.ts.map +1 -1
- package/lib/values.js +10 -14
- package/lib/values.js.map +2 -2
- package/lib/values.mjs +10 -14
- package/lib/values.mjs.map +2 -2
- package/package.json +4 -9
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
1
41
|
// src/executeWithoutSchema.ts
|
|
2
42
|
import {
|
|
3
43
|
GraphQLEnumType,
|
|
@@ -8,7 +48,13 @@ import {
|
|
|
8
48
|
Kind,
|
|
9
49
|
locatedError
|
|
10
50
|
} from "graphql";
|
|
11
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
OperationTypeNode
|
|
53
|
+
} from "./supermassive-ast/index.mjs";
|
|
54
|
+
import {
|
|
55
|
+
collectFields,
|
|
56
|
+
collectSubfields as _collectSubfields
|
|
57
|
+
} from "./collectFields.mjs";
|
|
12
58
|
import { devAssert } from "./jsutils/devAssert.mjs";
|
|
13
59
|
import { inspect } from "./jsutils/inspect.mjs";
|
|
14
60
|
import { invariant } from "./jsutils/invariant.mjs";
|
|
@@ -24,49 +70,31 @@ import { typeNameFromAST } from "./utilities/typeNameFromAST.mjs";
|
|
|
24
70
|
import {
|
|
25
71
|
getArgumentValues,
|
|
26
72
|
getVariableValues,
|
|
27
|
-
specifiedScalars
|
|
73
|
+
specifiedScalars,
|
|
74
|
+
getDirectiveValues
|
|
28
75
|
} from "./values.mjs";
|
|
29
76
|
import { arraysAreEqual } from "./utilities/array.mjs";
|
|
77
|
+
import { isAsyncIterable } from "./jsutils/isAsyncIterable.mjs";
|
|
78
|
+
import { mapAsyncIterator } from "./utilities/mapAsyncIterator.mjs";
|
|
79
|
+
import { GraphQLStreamDirective } from "./directives.mjs";
|
|
80
|
+
import { memoize3 } from "./jsutils/memoize3.mjs";
|
|
81
|
+
var collectSubfields = memoize3(
|
|
82
|
+
(exeContext, returnTypeName, fieldGroup) => _collectSubfields(
|
|
83
|
+
exeContext.resolvers,
|
|
84
|
+
exeContext.fragments,
|
|
85
|
+
exeContext.variableValues,
|
|
86
|
+
exeContext.operation,
|
|
87
|
+
returnTypeName.name,
|
|
88
|
+
fieldGroup
|
|
89
|
+
)
|
|
90
|
+
);
|
|
30
91
|
function executeWithoutSchema(args) {
|
|
31
|
-
const
|
|
32
|
-
resolvers,
|
|
33
|
-
schemaResolvers,
|
|
34
|
-
document,
|
|
35
|
-
rootValue,
|
|
36
|
-
contextValue,
|
|
37
|
-
variableValues,
|
|
38
|
-
operationName,
|
|
39
|
-
fieldResolver,
|
|
40
|
-
typeResolver,
|
|
41
|
-
fieldExecutionHooks
|
|
42
|
-
} = args;
|
|
43
|
-
const combinedResolvers = schemaResolvers ? mergeResolvers(resolvers, schemaResolvers) : resolvers;
|
|
44
|
-
assertValidExecutionArguments(document, variableValues);
|
|
45
|
-
const exeContext = buildExecutionContext(
|
|
46
|
-
combinedResolvers,
|
|
47
|
-
document,
|
|
48
|
-
rootValue,
|
|
49
|
-
contextValue,
|
|
50
|
-
variableValues,
|
|
51
|
-
operationName,
|
|
52
|
-
fieldResolver,
|
|
53
|
-
typeResolver,
|
|
54
|
-
fieldExecutionHooks
|
|
55
|
-
);
|
|
92
|
+
const exeContext = buildExecutionContext(args);
|
|
56
93
|
if (!("resolvers" in exeContext)) {
|
|
57
94
|
return { errors: exeContext };
|
|
58
95
|
} else {
|
|
59
|
-
|
|
60
|
-
return buildResponse(exeContext, data);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function buildResponse(exeContext, data) {
|
|
64
|
-
if (isPromise(data)) {
|
|
65
|
-
return data.then(
|
|
66
|
-
(resolved) => buildResponse(exeContext, resolved)
|
|
67
|
-
);
|
|
96
|
+
return executeOperation(exeContext);
|
|
68
97
|
}
|
|
69
|
-
return exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
70
98
|
}
|
|
71
99
|
function assertValidExecutionArguments(document, rawVariableValues) {
|
|
72
100
|
devAssert(document, "Must provide document.");
|
|
@@ -75,8 +103,24 @@ function assertValidExecutionArguments(document, rawVariableValues) {
|
|
|
75
103
|
"Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided."
|
|
76
104
|
);
|
|
77
105
|
}
|
|
78
|
-
function buildExecutionContext(
|
|
106
|
+
function buildExecutionContext(args) {
|
|
79
107
|
var _a, _b;
|
|
108
|
+
const {
|
|
109
|
+
resolvers,
|
|
110
|
+
schemaResolvers,
|
|
111
|
+
document,
|
|
112
|
+
rootValue,
|
|
113
|
+
contextValue,
|
|
114
|
+
buildContextValue,
|
|
115
|
+
variableValues,
|
|
116
|
+
operationName,
|
|
117
|
+
fieldResolver,
|
|
118
|
+
typeResolver,
|
|
119
|
+
subscribeFieldResolver,
|
|
120
|
+
fieldExecutionHooks
|
|
121
|
+
} = args;
|
|
122
|
+
assertValidExecutionArguments(document, variableValues);
|
|
123
|
+
const combinedResolvers = schemaResolvers ? mergeResolvers(resolvers, schemaResolvers) : resolvers;
|
|
80
124
|
let operation;
|
|
81
125
|
const fragments = /* @__PURE__ */ Object.create(null);
|
|
82
126
|
for (const definition of document.definitions) {
|
|
@@ -108,64 +152,135 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
108
152
|
}
|
|
109
153
|
const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
|
|
110
154
|
const coercedVariableValues = getVariableValues(
|
|
111
|
-
|
|
155
|
+
combinedResolvers,
|
|
112
156
|
variableDefinitions,
|
|
113
|
-
|
|
157
|
+
variableValues != null ? variableValues : {},
|
|
114
158
|
{ maxErrors: 50 }
|
|
115
159
|
);
|
|
116
160
|
if (coercedVariableValues.errors) {
|
|
117
161
|
return coercedVariableValues.errors;
|
|
118
162
|
}
|
|
119
163
|
return {
|
|
120
|
-
resolvers,
|
|
164
|
+
resolvers: combinedResolvers,
|
|
121
165
|
fragments,
|
|
122
166
|
rootValue,
|
|
123
|
-
contextValue,
|
|
167
|
+
contextValue: buildContextValue ? buildContextValue(contextValue) : contextValue,
|
|
168
|
+
buildContextValue,
|
|
124
169
|
operation,
|
|
125
170
|
variableValues: coercedVariableValues.coerced,
|
|
126
171
|
fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
|
|
127
172
|
typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
|
|
173
|
+
subscribeFieldResolver: subscribeFieldResolver != null ? subscribeFieldResolver : defaultFieldResolver,
|
|
128
174
|
errors: [],
|
|
129
|
-
fieldExecutionHooks
|
|
175
|
+
fieldExecutionHooks,
|
|
176
|
+
subsequentPayloads: /* @__PURE__ */ new Set()
|
|
130
177
|
};
|
|
131
178
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
179
|
+
function buildPerEventExecutionContext(exeContext, payload) {
|
|
180
|
+
return __spreadProps(__spreadValues({}, exeContext), {
|
|
181
|
+
contextValue: exeContext.buildContextValue ? exeContext.buildContextValue(exeContext.contextValue) : exeContext.contextValue,
|
|
182
|
+
rootValue: payload,
|
|
183
|
+
subsequentPayloads: /* @__PURE__ */ new Set(),
|
|
184
|
+
errors: []
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function executeOperation(exeContext) {
|
|
188
|
+
const { operation, rootValue, resolvers, fragments, variableValues } = exeContext;
|
|
189
|
+
const rootTypeName = getOperationRootTypeName(operation);
|
|
190
|
+
const { groupedFieldSet, patches } = collectFields(
|
|
191
|
+
resolvers,
|
|
192
|
+
fragments,
|
|
193
|
+
variableValues,
|
|
194
|
+
rootTypeName,
|
|
195
|
+
operation
|
|
142
196
|
);
|
|
143
197
|
const path = void 0;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
198
|
+
let result;
|
|
199
|
+
switch (operation.operation) {
|
|
200
|
+
case OperationTypeNode.QUERY:
|
|
201
|
+
result = executeFields(
|
|
202
|
+
exeContext,
|
|
203
|
+
rootTypeName,
|
|
204
|
+
rootValue,
|
|
205
|
+
path,
|
|
206
|
+
groupedFieldSet,
|
|
207
|
+
void 0
|
|
208
|
+
);
|
|
209
|
+
result = buildResponse(exeContext, result);
|
|
210
|
+
break;
|
|
211
|
+
case OperationTypeNode.MUTATION:
|
|
212
|
+
result = executeFieldsSerially(
|
|
213
|
+
exeContext,
|
|
214
|
+
rootTypeName,
|
|
215
|
+
rootValue,
|
|
216
|
+
path,
|
|
217
|
+
groupedFieldSet
|
|
218
|
+
);
|
|
219
|
+
result = buildResponse(exeContext, result);
|
|
220
|
+
break;
|
|
221
|
+
case OperationTypeNode.SUBSCRIPTION: {
|
|
222
|
+
const resultOrStreamOrPromise = createSourceEventStream(exeContext);
|
|
223
|
+
result = mapResultOrEventStreamOrPromise(
|
|
224
|
+
resultOrStreamOrPromise,
|
|
225
|
+
exeContext,
|
|
226
|
+
rootTypeName,
|
|
227
|
+
path,
|
|
228
|
+
groupedFieldSet
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const patch of patches) {
|
|
233
|
+
const { label, groupedFieldSet: patchGroupedFieldSet } = patch;
|
|
234
|
+
executeDeferredFragment(
|
|
235
|
+
exeContext,
|
|
236
|
+
rootTypeName,
|
|
237
|
+
rootValue,
|
|
238
|
+
patchGroupedFieldSet,
|
|
239
|
+
label,
|
|
240
|
+
path
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
function buildResponse(exeContext, data) {
|
|
246
|
+
if (isPromise(data)) {
|
|
247
|
+
return data.then(
|
|
248
|
+
(resolved) => buildResponse(exeContext, resolved),
|
|
249
|
+
(error) => {
|
|
148
250
|
exeContext.errors.push(error);
|
|
149
|
-
return
|
|
150
|
-
}
|
|
251
|
+
return buildResponse(exeContext, null);
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const initialResult = exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
257
|
+
if (exeContext.subsequentPayloads.size > 0) {
|
|
258
|
+
return {
|
|
259
|
+
initialResult: __spreadProps(__spreadValues({}, initialResult), {
|
|
260
|
+
hasNext: true
|
|
261
|
+
}),
|
|
262
|
+
subsequentResults: yieldSubsequentPayloads(exeContext)
|
|
263
|
+
};
|
|
264
|
+
} else {
|
|
265
|
+
return initialResult;
|
|
151
266
|
}
|
|
152
|
-
return result;
|
|
153
267
|
} catch (error) {
|
|
154
268
|
exeContext.errors.push(error);
|
|
155
|
-
return null;
|
|
269
|
+
return buildResponse(exeContext, null);
|
|
156
270
|
}
|
|
157
271
|
}
|
|
158
|
-
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path,
|
|
272
|
+
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, groupedFieldSet) {
|
|
159
273
|
return promiseReduce(
|
|
160
|
-
|
|
161
|
-
(results, [responseName,
|
|
274
|
+
groupedFieldSet,
|
|
275
|
+
(results, [responseName, fieldGroup]) => {
|
|
162
276
|
const fieldPath = addPath(path, responseName, parentTypeName);
|
|
163
277
|
const result = executeField(
|
|
164
278
|
exeContext,
|
|
165
279
|
parentTypeName,
|
|
166
280
|
sourceValue,
|
|
167
|
-
|
|
168
|
-
fieldPath
|
|
281
|
+
fieldGroup,
|
|
282
|
+
fieldPath,
|
|
283
|
+
void 0
|
|
169
284
|
);
|
|
170
285
|
if (result === void 0) {
|
|
171
286
|
return results;
|
|
@@ -182,17 +297,18 @@ function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, fi
|
|
|
182
297
|
/* @__PURE__ */ Object.create(null)
|
|
183
298
|
);
|
|
184
299
|
}
|
|
185
|
-
function executeFields(exeContext, parentTypeName, sourceValue, path,
|
|
300
|
+
function executeFields(exeContext, parentTypeName, sourceValue, path, groupedFieldSet, incrementalDataRecord) {
|
|
186
301
|
const results = /* @__PURE__ */ Object.create(null);
|
|
187
302
|
let containsPromise = false;
|
|
188
|
-
for (const [responseName,
|
|
303
|
+
for (const [responseName, fieldGroup] of groupedFieldSet) {
|
|
189
304
|
const fieldPath = addPath(path, responseName, parentTypeName);
|
|
190
305
|
const result = executeField(
|
|
191
306
|
exeContext,
|
|
192
307
|
parentTypeName,
|
|
193
308
|
sourceValue,
|
|
194
|
-
|
|
195
|
-
fieldPath
|
|
309
|
+
fieldGroup,
|
|
310
|
+
fieldPath,
|
|
311
|
+
incrementalDataRecord
|
|
196
312
|
);
|
|
197
313
|
if (result !== void 0) {
|
|
198
314
|
results[responseName] = result;
|
|
@@ -206,9 +322,8 @@ function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
|
206
322
|
}
|
|
207
323
|
return promiseForObject(results);
|
|
208
324
|
}
|
|
209
|
-
function executeField(exeContext, parentTypeName, source,
|
|
210
|
-
const fieldName =
|
|
211
|
-
const hooks = exeContext.fieldExecutionHooks;
|
|
325
|
+
function executeField(exeContext, parentTypeName, source, fieldGroup, path, incrementalDataRecord) {
|
|
326
|
+
const fieldName = fieldGroup[0].name.value;
|
|
212
327
|
let resolveFn;
|
|
213
328
|
let returnTypeName;
|
|
214
329
|
let returnTypeNode;
|
|
@@ -223,7 +338,7 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
223
338
|
}
|
|
224
339
|
};
|
|
225
340
|
} else {
|
|
226
|
-
returnTypeNode =
|
|
341
|
+
returnTypeNode = fieldGroup[0].__type;
|
|
227
342
|
returnTypeName = typeNameFromAST(returnTypeNode);
|
|
228
343
|
const typeResolvers = exeContext.resolvers[parentTypeName];
|
|
229
344
|
resolveFn = typeResolvers == null ? void 0 : typeResolvers[fieldName];
|
|
@@ -238,22 +353,187 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
238
353
|
const info = buildResolveInfo(
|
|
239
354
|
exeContext,
|
|
240
355
|
fieldName,
|
|
241
|
-
|
|
356
|
+
fieldGroup,
|
|
242
357
|
parentTypeName,
|
|
243
358
|
returnTypeName,
|
|
244
359
|
returnTypeNode,
|
|
245
360
|
path
|
|
246
361
|
);
|
|
362
|
+
return resolveAndCompleteField(
|
|
363
|
+
exeContext,
|
|
364
|
+
returnTypeNode,
|
|
365
|
+
fieldGroup,
|
|
366
|
+
info,
|
|
367
|
+
path,
|
|
368
|
+
resolveFn,
|
|
369
|
+
source,
|
|
370
|
+
incrementalDataRecord,
|
|
371
|
+
isDefaultResolverUsed
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
function createSourceEventStream(exeContext) {
|
|
375
|
+
try {
|
|
376
|
+
const eventStream = executeSubscriptionImpl(exeContext);
|
|
377
|
+
if (isPromise(eventStream)) {
|
|
378
|
+
return eventStream.then(void 0, (error) => ({ errors: [error] }));
|
|
379
|
+
}
|
|
380
|
+
return eventStream;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
return { errors: [error] };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function executeSubscriptionImpl(exeContext) {
|
|
386
|
+
const { resolvers, fragments, operation, variableValues, rootValue } = exeContext;
|
|
387
|
+
const typeName = getOperationRootTypeName(operation);
|
|
388
|
+
const { groupedFieldSet } = collectFields(
|
|
389
|
+
resolvers,
|
|
390
|
+
fragments,
|
|
391
|
+
variableValues,
|
|
392
|
+
typeName,
|
|
393
|
+
operation
|
|
394
|
+
);
|
|
395
|
+
const firstRootField = groupedFieldSet.entries().next().value;
|
|
396
|
+
const [responseName, fieldGroup] = firstRootField;
|
|
397
|
+
const fieldName = fieldGroup[0].name.value;
|
|
398
|
+
let resolveFn;
|
|
399
|
+
let returnTypeName;
|
|
400
|
+
let returnTypeNode;
|
|
401
|
+
if (fieldName === "__typename" && !resolveFn) {
|
|
402
|
+
resolveFn = () => typeName;
|
|
403
|
+
returnTypeName = "String";
|
|
404
|
+
returnTypeNode = {
|
|
405
|
+
kind: Kind.NAMED_TYPE,
|
|
406
|
+
name: {
|
|
407
|
+
kind: Kind.NAME,
|
|
408
|
+
value: "String"
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
} else {
|
|
412
|
+
returnTypeNode = fieldGroup[0].__type;
|
|
413
|
+
returnTypeName = typeNameFromAST(returnTypeNode);
|
|
414
|
+
const typeResolvers = exeContext.resolvers[typeName];
|
|
415
|
+
const fieldResolver = typeResolvers == null ? void 0 : typeResolvers[fieldName];
|
|
416
|
+
resolveFn = fieldResolver == null ? void 0 : fieldResolver.subscribe;
|
|
417
|
+
}
|
|
418
|
+
if (!resolveFn) {
|
|
419
|
+
resolveFn = exeContext.subscribeFieldResolver;
|
|
420
|
+
}
|
|
421
|
+
const path = addPath(void 0, responseName, typeName);
|
|
422
|
+
const info = buildResolveInfo(
|
|
423
|
+
exeContext,
|
|
424
|
+
fieldName,
|
|
425
|
+
fieldGroup,
|
|
426
|
+
typeName,
|
|
427
|
+
returnTypeName,
|
|
428
|
+
returnTypeNode,
|
|
429
|
+
path
|
|
430
|
+
);
|
|
431
|
+
try {
|
|
432
|
+
const args = getArgumentValues(resolvers, fieldGroup[0], variableValues);
|
|
433
|
+
const contextValue = exeContext.contextValue;
|
|
434
|
+
const result = resolveFn(rootValue, args, contextValue, info);
|
|
435
|
+
if (isPromise(result)) {
|
|
436
|
+
return result.then(assertEventStream).then(void 0, (error) => {
|
|
437
|
+
throw locatedError(
|
|
438
|
+
error,
|
|
439
|
+
fieldGroup,
|
|
440
|
+
pathToArray(path)
|
|
441
|
+
);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
return assertEventStream(result);
|
|
445
|
+
} catch (error) {
|
|
446
|
+
throw locatedError(
|
|
447
|
+
error,
|
|
448
|
+
fieldGroup,
|
|
449
|
+
pathToArray(path)
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function assertEventStream(result) {
|
|
454
|
+
if (result instanceof Error) {
|
|
455
|
+
throw result;
|
|
456
|
+
}
|
|
457
|
+
if (!isAsyncIterable(result)) {
|
|
458
|
+
throw new GraphQLError(
|
|
459
|
+
`Subscription field must return Async Iterable. Received: ${inspect(result)}.`
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, parentTypeName, path, groupedFieldSet) {
|
|
465
|
+
if (isPromise(resultOrStreamOrPromise)) {
|
|
466
|
+
return resultOrStreamOrPromise.then(
|
|
467
|
+
(resultOrStream) => mapResultOrEventStreamOrPromise(
|
|
468
|
+
resultOrStream,
|
|
469
|
+
exeContext,
|
|
470
|
+
parentTypeName,
|
|
471
|
+
path,
|
|
472
|
+
groupedFieldSet
|
|
473
|
+
)
|
|
474
|
+
);
|
|
475
|
+
} else {
|
|
476
|
+
if (!isAsyncIterable(resultOrStreamOrPromise)) {
|
|
477
|
+
return resultOrStreamOrPromise;
|
|
478
|
+
} else {
|
|
479
|
+
const mapSourceToResponse = (payload) => {
|
|
480
|
+
const perEventContext = buildPerEventExecutionContext(
|
|
481
|
+
exeContext,
|
|
482
|
+
payload
|
|
483
|
+
);
|
|
484
|
+
const data = executeFields(
|
|
485
|
+
exeContext,
|
|
486
|
+
parentTypeName,
|
|
487
|
+
payload,
|
|
488
|
+
path,
|
|
489
|
+
groupedFieldSet,
|
|
490
|
+
void 0
|
|
491
|
+
);
|
|
492
|
+
return buildResponse(perEventContext, data);
|
|
493
|
+
};
|
|
494
|
+
return mapAsyncIterator(resultOrStreamOrPromise, mapSourceToResponse);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function buildResolveInfo(exeContext, fieldName, fieldGroup, parentTypeName, returnTypeName, returnTypeNode, path) {
|
|
499
|
+
return {
|
|
500
|
+
fieldName,
|
|
501
|
+
fieldGroup,
|
|
502
|
+
returnTypeName,
|
|
503
|
+
parentTypeName,
|
|
504
|
+
returnTypeNode,
|
|
505
|
+
path,
|
|
506
|
+
fragments: exeContext.fragments,
|
|
507
|
+
rootValue: exeContext.rootValue,
|
|
508
|
+
operation: exeContext.operation,
|
|
509
|
+
variableValues: exeContext.variableValues
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function handleFieldError(rawError, exeContext, returnTypeNode, fieldGroup, path, incrementalDataRecord) {
|
|
513
|
+
var _a;
|
|
514
|
+
const error = locatedError(
|
|
515
|
+
rawError,
|
|
516
|
+
fieldGroup,
|
|
517
|
+
pathToArray(path)
|
|
518
|
+
);
|
|
519
|
+
if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
const errors = (_a = incrementalDataRecord == null ? void 0 : incrementalDataRecord.errors) != null ? _a : exeContext.errors;
|
|
523
|
+
errors.push(error);
|
|
524
|
+
}
|
|
525
|
+
function resolveAndCompleteField(exeContext, returnTypeNode, fieldGroup, info, path, resolveFn, source, incrementalDataRecord, isDefaultResolverUsed) {
|
|
526
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
247
527
|
try {
|
|
248
528
|
const args = getArgumentValues(
|
|
249
529
|
exeContext.resolvers,
|
|
250
|
-
|
|
530
|
+
fieldGroup[0],
|
|
251
531
|
exeContext.variableValues
|
|
252
532
|
);
|
|
533
|
+
const contextValue = exeContext.contextValue;
|
|
253
534
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
254
535
|
invokeBeforeFieldResolveHook(info, exeContext);
|
|
255
536
|
}
|
|
256
|
-
const contextValue = exeContext.contextValue;
|
|
257
537
|
const result = resolveFn(source, args, contextValue, info);
|
|
258
538
|
let completed;
|
|
259
539
|
if (isPromise(result)) {
|
|
@@ -265,10 +545,11 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
265
545
|
return completeValue(
|
|
266
546
|
exeContext,
|
|
267
547
|
returnTypeNode,
|
|
268
|
-
|
|
548
|
+
fieldGroup,
|
|
269
549
|
info,
|
|
270
550
|
path,
|
|
271
|
-
resolved
|
|
551
|
+
resolved,
|
|
552
|
+
incrementalDataRecord
|
|
272
553
|
);
|
|
273
554
|
},
|
|
274
555
|
(rawError) => {
|
|
@@ -285,10 +566,11 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
285
566
|
completed = completeValue(
|
|
286
567
|
exeContext,
|
|
287
568
|
returnTypeNode,
|
|
288
|
-
|
|
569
|
+
fieldGroup,
|
|
289
570
|
info,
|
|
290
571
|
path,
|
|
291
|
-
result
|
|
572
|
+
result,
|
|
573
|
+
incrementalDataRecord
|
|
292
574
|
);
|
|
293
575
|
}
|
|
294
576
|
if (isPromise(completed)) {
|
|
@@ -302,13 +584,21 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
302
584
|
(rawError) => {
|
|
303
585
|
const error = locatedError(
|
|
304
586
|
rawError,
|
|
305
|
-
|
|
587
|
+
fieldGroup,
|
|
306
588
|
pathToArray(path)
|
|
307
589
|
);
|
|
308
590
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
309
591
|
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
310
592
|
}
|
|
311
|
-
|
|
593
|
+
handleFieldError(
|
|
594
|
+
rawError,
|
|
595
|
+
exeContext,
|
|
596
|
+
returnTypeNode,
|
|
597
|
+
fieldGroup,
|
|
598
|
+
path,
|
|
599
|
+
incrementalDataRecord
|
|
600
|
+
);
|
|
601
|
+
return null;
|
|
312
602
|
}
|
|
313
603
|
);
|
|
314
604
|
}
|
|
@@ -320,7 +610,7 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
320
610
|
const pathArray = pathToArray(path);
|
|
321
611
|
const error = locatedError(
|
|
322
612
|
rawError,
|
|
323
|
-
|
|
613
|
+
fieldGroup,
|
|
324
614
|
pathArray
|
|
325
615
|
);
|
|
326
616
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve) && error.path && arraysAreEqual(pathArray, error.path)) {
|
|
@@ -329,31 +619,18 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
329
619
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
330
620
|
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
331
621
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
returnTypeNode,
|
|
342
|
-
path,
|
|
343
|
-
fragments: exeContext.fragments,
|
|
344
|
-
rootValue: exeContext.rootValue,
|
|
345
|
-
operation: exeContext.operation,
|
|
346
|
-
variableValues: exeContext.variableValues
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
function handleFieldError(error, returnTypeNode, exeContext) {
|
|
350
|
-
if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
|
|
351
|
-
throw error;
|
|
622
|
+
handleFieldError(
|
|
623
|
+
rawError,
|
|
624
|
+
exeContext,
|
|
625
|
+
returnTypeNode,
|
|
626
|
+
fieldGroup,
|
|
627
|
+
path,
|
|
628
|
+
incrementalDataRecord
|
|
629
|
+
);
|
|
630
|
+
return null;
|
|
352
631
|
}
|
|
353
|
-
exeContext.errors.push(error);
|
|
354
|
-
return null;
|
|
355
632
|
}
|
|
356
|
-
function completeValue(exeContext, returnTypeNode,
|
|
633
|
+
function completeValue(exeContext, returnTypeNode, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
357
634
|
if (result instanceof Error) {
|
|
358
635
|
throw result;
|
|
359
636
|
}
|
|
@@ -361,10 +638,11 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
361
638
|
const completed = completeValue(
|
|
362
639
|
exeContext,
|
|
363
640
|
returnTypeNode.type,
|
|
364
|
-
|
|
641
|
+
fieldGroup,
|
|
365
642
|
info,
|
|
366
643
|
path,
|
|
367
|
-
result
|
|
644
|
+
result,
|
|
645
|
+
incrementalDataRecord
|
|
368
646
|
);
|
|
369
647
|
if (completed === null) {
|
|
370
648
|
throw new Error(
|
|
@@ -379,11 +657,12 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
379
657
|
if (returnTypeNode.kind === Kind.LIST_TYPE) {
|
|
380
658
|
return completeListValue(
|
|
381
659
|
exeContext,
|
|
382
|
-
returnTypeNode
|
|
383
|
-
|
|
660
|
+
returnTypeNode,
|
|
661
|
+
fieldGroup,
|
|
384
662
|
info,
|
|
385
663
|
path,
|
|
386
|
-
result
|
|
664
|
+
result,
|
|
665
|
+
incrementalDataRecord
|
|
387
666
|
);
|
|
388
667
|
}
|
|
389
668
|
const returnTypeName = returnTypeNode.name.value;
|
|
@@ -400,20 +679,21 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
400
679
|
return completeAbstractValue(
|
|
401
680
|
exeContext,
|
|
402
681
|
returnType,
|
|
403
|
-
|
|
682
|
+
fieldGroup,
|
|
404
683
|
info,
|
|
405
684
|
path,
|
|
406
|
-
result
|
|
685
|
+
result,
|
|
686
|
+
incrementalDataRecord
|
|
407
687
|
);
|
|
408
688
|
}
|
|
409
689
|
if (typeof returnType === "object") {
|
|
410
690
|
return completeObjectValue(
|
|
411
691
|
exeContext,
|
|
412
692
|
returnTypeName,
|
|
413
|
-
|
|
414
|
-
info,
|
|
693
|
+
fieldGroup,
|
|
415
694
|
path,
|
|
416
|
-
result
|
|
695
|
+
result,
|
|
696
|
+
incrementalDataRecord
|
|
417
697
|
);
|
|
418
698
|
}
|
|
419
699
|
invariant(
|
|
@@ -421,60 +701,235 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
421
701
|
"Cannot complete value of unexpected output type: " + inspect(returnType)
|
|
422
702
|
);
|
|
423
703
|
}
|
|
424
|
-
function
|
|
704
|
+
function completePromisedValue(exeContext, returnTypeNode, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
705
|
+
return __async(this, null, function* () {
|
|
706
|
+
try {
|
|
707
|
+
const resolved = yield result;
|
|
708
|
+
let completed = completeValue(
|
|
709
|
+
exeContext,
|
|
710
|
+
returnTypeNode,
|
|
711
|
+
fieldGroup,
|
|
712
|
+
info,
|
|
713
|
+
path,
|
|
714
|
+
resolved,
|
|
715
|
+
incrementalDataRecord
|
|
716
|
+
);
|
|
717
|
+
if (isPromise(completed)) {
|
|
718
|
+
completed = yield completed;
|
|
719
|
+
}
|
|
720
|
+
return completed;
|
|
721
|
+
} catch (rawError) {
|
|
722
|
+
handleFieldError(
|
|
723
|
+
rawError,
|
|
724
|
+
exeContext,
|
|
725
|
+
returnTypeNode,
|
|
726
|
+
fieldGroup,
|
|
727
|
+
path,
|
|
728
|
+
incrementalDataRecord
|
|
729
|
+
);
|
|
730
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
function completeListValue(exeContext, returnTypeNode, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
736
|
+
const itemType = returnTypeNode.type;
|
|
737
|
+
if (isAsyncIterable(result)) {
|
|
738
|
+
const asyncIterator = result[Symbol.asyncIterator]();
|
|
739
|
+
return completeAsyncIteratorValue(
|
|
740
|
+
exeContext,
|
|
741
|
+
itemType,
|
|
742
|
+
fieldGroup,
|
|
743
|
+
info,
|
|
744
|
+
path,
|
|
745
|
+
asyncIterator,
|
|
746
|
+
incrementalDataRecord
|
|
747
|
+
);
|
|
748
|
+
}
|
|
425
749
|
if (!isIterableObject(result)) {
|
|
426
750
|
throw new GraphQLError(
|
|
427
751
|
`Expected Iterable, but did not find one for field "${info.parentTypeName}.${info.fieldName}".`
|
|
428
752
|
);
|
|
429
753
|
}
|
|
754
|
+
const stream = getStreamValues(exeContext, fieldGroup, path);
|
|
430
755
|
let containsPromise = false;
|
|
431
|
-
|
|
756
|
+
let previousIncrementalDataRecord = incrementalDataRecord;
|
|
757
|
+
const completedResults = [];
|
|
758
|
+
let index = 0;
|
|
759
|
+
for (const item of result) {
|
|
432
760
|
const itemPath = addPath(path, index, void 0);
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
761
|
+
if (stream && typeof stream.initialCount === "number" && index >= stream.initialCount) {
|
|
762
|
+
previousIncrementalDataRecord = executeStreamField(
|
|
763
|
+
path,
|
|
764
|
+
itemPath,
|
|
765
|
+
item,
|
|
766
|
+
exeContext,
|
|
767
|
+
fieldGroup,
|
|
768
|
+
info,
|
|
769
|
+
itemType,
|
|
770
|
+
stream.label,
|
|
771
|
+
previousIncrementalDataRecord
|
|
772
|
+
);
|
|
773
|
+
index++;
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
if (completeListItemValue(
|
|
777
|
+
item,
|
|
778
|
+
completedResults,
|
|
779
|
+
exeContext,
|
|
780
|
+
itemType,
|
|
781
|
+
fieldGroup,
|
|
782
|
+
info,
|
|
783
|
+
itemPath,
|
|
784
|
+
incrementalDataRecord
|
|
785
|
+
)) {
|
|
786
|
+
containsPromise = true;
|
|
787
|
+
}
|
|
788
|
+
index++;
|
|
789
|
+
}
|
|
790
|
+
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
791
|
+
}
|
|
792
|
+
function completeListItemValue(item, completedResults, exeContext, itemTypeNode, fieldGroup, info, itemPath, incrementalDataRecord) {
|
|
793
|
+
if (isPromise(item)) {
|
|
794
|
+
completedResults.push(
|
|
795
|
+
completePromisedValue(
|
|
796
|
+
exeContext,
|
|
797
|
+
itemTypeNode,
|
|
798
|
+
fieldGroup,
|
|
799
|
+
info,
|
|
800
|
+
itemPath,
|
|
801
|
+
item,
|
|
802
|
+
incrementalDataRecord
|
|
803
|
+
)
|
|
804
|
+
);
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
try {
|
|
808
|
+
const completedItem = completeValue(
|
|
809
|
+
exeContext,
|
|
810
|
+
itemTypeNode,
|
|
811
|
+
fieldGroup,
|
|
812
|
+
info,
|
|
813
|
+
itemPath,
|
|
814
|
+
item,
|
|
815
|
+
incrementalDataRecord
|
|
816
|
+
);
|
|
817
|
+
if (isPromise(completedItem)) {
|
|
818
|
+
completedResults.push(
|
|
819
|
+
completedItem.then(void 0, (rawError) => {
|
|
820
|
+
handleFieldError(
|
|
821
|
+
rawError,
|
|
438
822
|
exeContext,
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
info,
|
|
823
|
+
itemTypeNode,
|
|
824
|
+
fieldGroup,
|
|
442
825
|
itemPath,
|
|
443
|
-
|
|
444
|
-
)
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
826
|
+
incrementalDataRecord
|
|
827
|
+
);
|
|
828
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
829
|
+
return null;
|
|
830
|
+
})
|
|
831
|
+
);
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
completedResults.push(completedItem);
|
|
835
|
+
} catch (rawError) {
|
|
836
|
+
handleFieldError(
|
|
837
|
+
rawError,
|
|
838
|
+
exeContext,
|
|
839
|
+
itemTypeNode,
|
|
840
|
+
fieldGroup,
|
|
841
|
+
itemPath,
|
|
842
|
+
incrementalDataRecord
|
|
843
|
+
);
|
|
844
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
845
|
+
completedResults.push(null);
|
|
846
|
+
}
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
function getStreamValues(exeContext, fieldGroup, path) {
|
|
850
|
+
if (typeof path.key === "number") {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const stream = getDirectiveValues(
|
|
854
|
+
GraphQLStreamDirective,
|
|
855
|
+
fieldGroup[0],
|
|
856
|
+
exeContext.resolvers,
|
|
857
|
+
exeContext.variableValues
|
|
858
|
+
);
|
|
859
|
+
if (!stream) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (stream.if === false) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
invariant(
|
|
866
|
+
typeof stream.initialCount === "number",
|
|
867
|
+
"initialCount must be a number"
|
|
868
|
+
);
|
|
869
|
+
invariant(
|
|
870
|
+
stream.initialCount >= 0,
|
|
871
|
+
"initialCount must be a positive integer"
|
|
872
|
+
);
|
|
873
|
+
invariant(
|
|
874
|
+
exeContext.operation.operation !== OperationTypeNode.SUBSCRIPTION,
|
|
875
|
+
"`@stream` directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`."
|
|
876
|
+
);
|
|
877
|
+
return {
|
|
878
|
+
initialCount: stream.initialCount,
|
|
879
|
+
label: typeof stream.label === "string" ? stream.label : void 0
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
function completeAsyncIteratorValue(exeContext, itemType, fieldGroup, info, path, asyncIterator, incrementalDataRecord) {
|
|
883
|
+
return __async(this, null, function* () {
|
|
884
|
+
const stream = getStreamValues(exeContext, fieldGroup, path);
|
|
885
|
+
let containsPromise = false;
|
|
886
|
+
const completedResults = [];
|
|
887
|
+
let index = 0;
|
|
888
|
+
while (true) {
|
|
889
|
+
if (stream && typeof stream.initialCount === "number" && index >= stream.initialCount) {
|
|
890
|
+
executeStreamAsyncIterator(
|
|
891
|
+
index,
|
|
892
|
+
asyncIterator,
|
|
448
893
|
exeContext,
|
|
449
|
-
|
|
450
|
-
fieldNodes,
|
|
894
|
+
fieldGroup,
|
|
451
895
|
info,
|
|
452
|
-
|
|
453
|
-
|
|
896
|
+
itemType,
|
|
897
|
+
path,
|
|
898
|
+
stream.label,
|
|
899
|
+
incrementalDataRecord
|
|
454
900
|
);
|
|
901
|
+
break;
|
|
455
902
|
}
|
|
456
|
-
|
|
903
|
+
const itemPath = addPath(path, index, void 0);
|
|
904
|
+
let iteration;
|
|
905
|
+
try {
|
|
906
|
+
iteration = yield asyncIterator.next();
|
|
907
|
+
if (iteration.done) {
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
} catch (rawError) {
|
|
911
|
+
throw locatedError(
|
|
912
|
+
rawError,
|
|
913
|
+
fieldGroup,
|
|
914
|
+
pathToArray(path)
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
if (completeListItemValue(
|
|
918
|
+
iteration.value,
|
|
919
|
+
completedResults,
|
|
920
|
+
exeContext,
|
|
921
|
+
itemType,
|
|
922
|
+
fieldGroup,
|
|
923
|
+
info,
|
|
924
|
+
itemPath,
|
|
925
|
+
incrementalDataRecord
|
|
926
|
+
)) {
|
|
457
927
|
containsPromise = true;
|
|
458
|
-
return completedItem.then(void 0, (rawError) => {
|
|
459
|
-
const error = locatedError(
|
|
460
|
-
rawError,
|
|
461
|
-
fieldNodes,
|
|
462
|
-
pathToArray(itemPath)
|
|
463
|
-
);
|
|
464
|
-
return handleFieldError(error, returnTypeNode, exeContext);
|
|
465
|
-
});
|
|
466
928
|
}
|
|
467
|
-
|
|
468
|
-
} catch (rawError) {
|
|
469
|
-
const error = locatedError(
|
|
470
|
-
rawError,
|
|
471
|
-
fieldNodes,
|
|
472
|
-
pathToArray(itemPath)
|
|
473
|
-
);
|
|
474
|
-
return handleFieldError(error, returnTypeNode, exeContext);
|
|
929
|
+
index += 1;
|
|
475
930
|
}
|
|
931
|
+
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
476
932
|
});
|
|
477
|
-
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
478
933
|
}
|
|
479
934
|
function completeLeafValue(returnType, result) {
|
|
480
935
|
const serializedResult = returnType.serialize(result);
|
|
@@ -485,7 +940,7 @@ function completeLeafValue(returnType, result) {
|
|
|
485
940
|
}
|
|
486
941
|
return serializedResult;
|
|
487
942
|
}
|
|
488
|
-
function completeAbstractValue(exeContext, returnType,
|
|
943
|
+
function completeAbstractValue(exeContext, returnType, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
489
944
|
var _a;
|
|
490
945
|
const resolveTypeFn = (_a = returnType.__resolveType) != null ? _a : exeContext.typeResolver;
|
|
491
946
|
const contextValue = exeContext.contextValue;
|
|
@@ -495,20 +950,20 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
495
950
|
(resolvedRuntimeTypeName) => completeObjectValue(
|
|
496
951
|
exeContext,
|
|
497
952
|
ensureValidRuntimeType(resolvedRuntimeTypeName, exeContext),
|
|
498
|
-
|
|
499
|
-
info,
|
|
953
|
+
fieldGroup,
|
|
500
954
|
path,
|
|
501
|
-
result
|
|
955
|
+
result,
|
|
956
|
+
incrementalDataRecord
|
|
502
957
|
)
|
|
503
958
|
);
|
|
504
959
|
}
|
|
505
960
|
return completeObjectValue(
|
|
506
961
|
exeContext,
|
|
507
962
|
ensureValidRuntimeType(runtimeTypeName, exeContext),
|
|
508
|
-
|
|
509
|
-
info,
|
|
963
|
+
fieldGroup,
|
|
510
964
|
path,
|
|
511
|
-
result
|
|
965
|
+
result,
|
|
966
|
+
incrementalDataRecord
|
|
512
967
|
);
|
|
513
968
|
}
|
|
514
969
|
function ensureValidRuntimeType(runtimeTypeName, exeContext) {
|
|
@@ -547,31 +1002,39 @@ function getRuntimeTypeInstanceName(runtimeType) {
|
|
|
547
1002
|
return "Unknown";
|
|
548
1003
|
}
|
|
549
1004
|
}
|
|
550
|
-
function completeObjectValue(exeContext, returnTypeName,
|
|
551
|
-
|
|
1005
|
+
function completeObjectValue(exeContext, returnTypeName, fieldGroup, path, result, incrementalDataRecord) {
|
|
1006
|
+
return collectAndExecuteSubfields(
|
|
552
1007
|
exeContext,
|
|
553
1008
|
returnTypeName,
|
|
554
|
-
|
|
1009
|
+
fieldGroup,
|
|
1010
|
+
path,
|
|
1011
|
+
result,
|
|
1012
|
+
incrementalDataRecord
|
|
555
1013
|
);
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1014
|
+
}
|
|
1015
|
+
function collectAndExecuteSubfields(exeContext, returnTypeName, fieldGroup, path, result, incrementalDataRecord) {
|
|
1016
|
+
const { groupedFieldSet: subGroupedFieldSet, patches: subPatches } = collectSubfields(exeContext, { name: returnTypeName }, fieldGroup);
|
|
1017
|
+
const subFields = executeFields(
|
|
1018
|
+
exeContext,
|
|
1019
|
+
returnTypeName,
|
|
1020
|
+
result,
|
|
1021
|
+
path,
|
|
1022
|
+
subGroupedFieldSet,
|
|
1023
|
+
incrementalDataRecord
|
|
1024
|
+
);
|
|
1025
|
+
for (const subPatch of subPatches) {
|
|
1026
|
+
const { label, groupedFieldSet: subPatchGroupedFieldSet } = subPatch;
|
|
1027
|
+
executeDeferredFragment(
|
|
1028
|
+
exeContext,
|
|
1029
|
+
returnTypeName,
|
|
1030
|
+
result,
|
|
1031
|
+
subPatchGroupedFieldSet,
|
|
1032
|
+
label,
|
|
1033
|
+
path,
|
|
1034
|
+
incrementalDataRecord
|
|
1035
|
+
);
|
|
573
1036
|
}
|
|
574
|
-
return
|
|
1037
|
+
return subFields;
|
|
575
1038
|
}
|
|
576
1039
|
function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
577
1040
|
var _a;
|
|
@@ -682,17 +1145,417 @@ var defaultFieldResolver = (
|
|
|
682
1145
|
);
|
|
683
1146
|
function getOperationRootTypeName(operation) {
|
|
684
1147
|
switch (operation.operation) {
|
|
685
|
-
case
|
|
1148
|
+
case OperationTypeNode.QUERY:
|
|
686
1149
|
return "Query";
|
|
687
|
-
case
|
|
1150
|
+
case OperationTypeNode.MUTATION:
|
|
688
1151
|
return "Mutation";
|
|
689
|
-
case
|
|
1152
|
+
case OperationTypeNode.SUBSCRIPTION:
|
|
690
1153
|
return "Subscription";
|
|
691
1154
|
}
|
|
692
1155
|
}
|
|
1156
|
+
function executeDeferredFragment(exeContext, parentTypeName, sourceValue, fields, label, path, parentContext) {
|
|
1157
|
+
const incrementalDataRecord = new DeferredFragmentRecord({
|
|
1158
|
+
label,
|
|
1159
|
+
path,
|
|
1160
|
+
parentContext,
|
|
1161
|
+
exeContext
|
|
1162
|
+
});
|
|
1163
|
+
let promiseOrData;
|
|
1164
|
+
try {
|
|
1165
|
+
promiseOrData = executeFields(
|
|
1166
|
+
exeContext,
|
|
1167
|
+
parentTypeName,
|
|
1168
|
+
sourceValue,
|
|
1169
|
+
path,
|
|
1170
|
+
fields,
|
|
1171
|
+
incrementalDataRecord
|
|
1172
|
+
);
|
|
1173
|
+
if (isPromise(promiseOrData)) {
|
|
1174
|
+
promiseOrData = promiseOrData.then(null, (e) => {
|
|
1175
|
+
incrementalDataRecord.errors.push(e);
|
|
1176
|
+
return null;
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
} catch (e) {
|
|
1180
|
+
incrementalDataRecord.errors.push(e);
|
|
1181
|
+
promiseOrData = null;
|
|
1182
|
+
}
|
|
1183
|
+
incrementalDataRecord.addData(promiseOrData);
|
|
1184
|
+
}
|
|
1185
|
+
function executeStreamField(path, itemPath, item, exeContext, fieldGroup, info, itemTypeNode, label, parentContext) {
|
|
1186
|
+
const incrementalDataRecord = new StreamItemsRecord({
|
|
1187
|
+
label,
|
|
1188
|
+
path: itemPath,
|
|
1189
|
+
parentContext,
|
|
1190
|
+
exeContext
|
|
1191
|
+
});
|
|
1192
|
+
if (isPromise(item)) {
|
|
1193
|
+
const completedItems = completePromisedValue(
|
|
1194
|
+
exeContext,
|
|
1195
|
+
itemTypeNode,
|
|
1196
|
+
fieldGroup,
|
|
1197
|
+
info,
|
|
1198
|
+
itemPath,
|
|
1199
|
+
item,
|
|
1200
|
+
incrementalDataRecord
|
|
1201
|
+
).then(
|
|
1202
|
+
(value) => [value],
|
|
1203
|
+
(error) => {
|
|
1204
|
+
incrementalDataRecord.errors.push(error);
|
|
1205
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
);
|
|
1209
|
+
incrementalDataRecord.addItems(completedItems);
|
|
1210
|
+
return incrementalDataRecord;
|
|
1211
|
+
}
|
|
1212
|
+
let completedItem;
|
|
1213
|
+
try {
|
|
1214
|
+
try {
|
|
1215
|
+
completedItem = completeValue(
|
|
1216
|
+
exeContext,
|
|
1217
|
+
itemTypeNode,
|
|
1218
|
+
fieldGroup,
|
|
1219
|
+
info,
|
|
1220
|
+
itemPath,
|
|
1221
|
+
item,
|
|
1222
|
+
incrementalDataRecord
|
|
1223
|
+
);
|
|
1224
|
+
} catch (rawError) {
|
|
1225
|
+
handleFieldError(
|
|
1226
|
+
rawError,
|
|
1227
|
+
exeContext,
|
|
1228
|
+
itemTypeNode,
|
|
1229
|
+
fieldGroup,
|
|
1230
|
+
itemPath,
|
|
1231
|
+
incrementalDataRecord
|
|
1232
|
+
);
|
|
1233
|
+
completedItem = null;
|
|
1234
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
1235
|
+
}
|
|
1236
|
+
} catch (error) {
|
|
1237
|
+
incrementalDataRecord.errors.push(error);
|
|
1238
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
1239
|
+
incrementalDataRecord.addItems(null);
|
|
1240
|
+
return incrementalDataRecord;
|
|
1241
|
+
}
|
|
1242
|
+
if (isPromise(completedItem)) {
|
|
1243
|
+
const completedItems = completedItem.then(void 0, (rawError) => {
|
|
1244
|
+
handleFieldError(
|
|
1245
|
+
rawError,
|
|
1246
|
+
exeContext,
|
|
1247
|
+
itemTypeNode,
|
|
1248
|
+
fieldGroup,
|
|
1249
|
+
itemPath,
|
|
1250
|
+
incrementalDataRecord
|
|
1251
|
+
);
|
|
1252
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
1253
|
+
return null;
|
|
1254
|
+
}).then(
|
|
1255
|
+
(value) => [value],
|
|
1256
|
+
(error) => {
|
|
1257
|
+
incrementalDataRecord.errors.push(error);
|
|
1258
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
1259
|
+
return null;
|
|
1260
|
+
}
|
|
1261
|
+
);
|
|
1262
|
+
incrementalDataRecord.addItems(completedItems);
|
|
1263
|
+
return incrementalDataRecord;
|
|
1264
|
+
}
|
|
1265
|
+
incrementalDataRecord.addItems([completedItem]);
|
|
1266
|
+
return incrementalDataRecord;
|
|
1267
|
+
}
|
|
1268
|
+
function executeStreamAsyncIteratorItem(asyncIterator, exeContext, fieldGroup, info, itemTypeNode, incrementalDataRecord, path, itemPath) {
|
|
1269
|
+
return __async(this, null, function* () {
|
|
1270
|
+
let item;
|
|
1271
|
+
try {
|
|
1272
|
+
const { value, done } = yield asyncIterator.next();
|
|
1273
|
+
if (done) {
|
|
1274
|
+
incrementalDataRecord.setIsCompletedAsyncIterator();
|
|
1275
|
+
return { done, value: void 0 };
|
|
1276
|
+
}
|
|
1277
|
+
item = value;
|
|
1278
|
+
} catch (rawError) {
|
|
1279
|
+
throw locatedError(
|
|
1280
|
+
rawError,
|
|
1281
|
+
fieldGroup,
|
|
1282
|
+
pathToArray(path)
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
let completedItem;
|
|
1286
|
+
try {
|
|
1287
|
+
completedItem = completeValue(
|
|
1288
|
+
exeContext,
|
|
1289
|
+
itemTypeNode,
|
|
1290
|
+
fieldGroup,
|
|
1291
|
+
info,
|
|
1292
|
+
itemPath,
|
|
1293
|
+
item,
|
|
1294
|
+
incrementalDataRecord
|
|
1295
|
+
);
|
|
1296
|
+
if (isPromise(completedItem)) {
|
|
1297
|
+
completedItem = completedItem.then(void 0, (rawError) => {
|
|
1298
|
+
handleFieldError(
|
|
1299
|
+
rawError,
|
|
1300
|
+
exeContext,
|
|
1301
|
+
itemTypeNode,
|
|
1302
|
+
fieldGroup,
|
|
1303
|
+
itemPath,
|
|
1304
|
+
incrementalDataRecord
|
|
1305
|
+
);
|
|
1306
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
1307
|
+
return null;
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
return { done: false, value: completedItem };
|
|
1311
|
+
} catch (rawError) {
|
|
1312
|
+
handleFieldError(
|
|
1313
|
+
rawError,
|
|
1314
|
+
exeContext,
|
|
1315
|
+
itemTypeNode,
|
|
1316
|
+
fieldGroup,
|
|
1317
|
+
itemPath,
|
|
1318
|
+
incrementalDataRecord
|
|
1319
|
+
);
|
|
1320
|
+
filterSubsequentPayloads(exeContext, itemPath, incrementalDataRecord);
|
|
1321
|
+
return { done: false, value: null };
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
function executeStreamAsyncIterator(initialIndex, asyncIterator, exeContext, fieldGroup, info, itemTypeNode, path, label, parentContext) {
|
|
1326
|
+
return __async(this, null, function* () {
|
|
1327
|
+
let index = initialIndex;
|
|
1328
|
+
let previousIncrementalDataRecord = parentContext != null ? parentContext : void 0;
|
|
1329
|
+
while (true) {
|
|
1330
|
+
const itemPath = addPath(path, index, void 0);
|
|
1331
|
+
const incrementalDataRecord = new StreamItemsRecord({
|
|
1332
|
+
label,
|
|
1333
|
+
path: itemPath,
|
|
1334
|
+
parentContext: previousIncrementalDataRecord,
|
|
1335
|
+
asyncIterator,
|
|
1336
|
+
exeContext
|
|
1337
|
+
});
|
|
1338
|
+
let iteration;
|
|
1339
|
+
try {
|
|
1340
|
+
iteration = yield executeStreamAsyncIteratorItem(
|
|
1341
|
+
asyncIterator,
|
|
1342
|
+
exeContext,
|
|
1343
|
+
fieldGroup,
|
|
1344
|
+
info,
|
|
1345
|
+
itemTypeNode,
|
|
1346
|
+
incrementalDataRecord,
|
|
1347
|
+
path,
|
|
1348
|
+
itemPath
|
|
1349
|
+
);
|
|
1350
|
+
} catch (error) {
|
|
1351
|
+
incrementalDataRecord.errors.push(error);
|
|
1352
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
1353
|
+
incrementalDataRecord.addItems(null);
|
|
1354
|
+
if (asyncIterator == null ? void 0 : asyncIterator.return) {
|
|
1355
|
+
asyncIterator.return().catch(() => {
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const { done, value: completedItem } = iteration;
|
|
1361
|
+
let completedItems;
|
|
1362
|
+
if (isPromise(completedItem)) {
|
|
1363
|
+
completedItems = completedItem.then(
|
|
1364
|
+
(value) => [value],
|
|
1365
|
+
(error) => {
|
|
1366
|
+
incrementalDataRecord.errors.push(error);
|
|
1367
|
+
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
|
|
1368
|
+
return null;
|
|
1369
|
+
}
|
|
1370
|
+
);
|
|
1371
|
+
} else {
|
|
1372
|
+
completedItems = [completedItem];
|
|
1373
|
+
}
|
|
1374
|
+
incrementalDataRecord.addItems(completedItems);
|
|
1375
|
+
if (done) {
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
previousIncrementalDataRecord = incrementalDataRecord;
|
|
1379
|
+
index++;
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
function filterSubsequentPayloads(exeContext, nullPath, currentIncrementalDataRecord) {
|
|
1384
|
+
const nullPathArray = pathToArray(nullPath);
|
|
1385
|
+
exeContext.subsequentPayloads.forEach((incrementalDataRecord) => {
|
|
1386
|
+
var _a;
|
|
1387
|
+
if (incrementalDataRecord === currentIncrementalDataRecord) {
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
for (let i = 0; i < nullPathArray.length; i++) {
|
|
1391
|
+
if (incrementalDataRecord.path[i] !== nullPathArray[i]) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (isStreamItemsRecord(incrementalDataRecord) && ((_a = incrementalDataRecord.asyncIterator) == null ? void 0 : _a.return)) {
|
|
1396
|
+
incrementalDataRecord.asyncIterator.return().catch(() => {
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
exeContext.subsequentPayloads.delete(incrementalDataRecord);
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
function getCompletedIncrementalResults(exeContext) {
|
|
1403
|
+
const incrementalResults = [];
|
|
1404
|
+
for (const incrementalDataRecord of exeContext.subsequentPayloads) {
|
|
1405
|
+
const incrementalResult = {};
|
|
1406
|
+
if (!incrementalDataRecord.isCompleted) {
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
exeContext.subsequentPayloads.delete(incrementalDataRecord);
|
|
1410
|
+
if (isStreamItemsRecord(incrementalDataRecord)) {
|
|
1411
|
+
const items = incrementalDataRecord.items;
|
|
1412
|
+
if (incrementalDataRecord.isCompletedAsyncIterator) {
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
incrementalResult.items = items;
|
|
1416
|
+
} else {
|
|
1417
|
+
const data = incrementalDataRecord.data;
|
|
1418
|
+
incrementalResult.data = data != null ? data : null;
|
|
1419
|
+
}
|
|
1420
|
+
incrementalResult.path = incrementalDataRecord.path;
|
|
1421
|
+
if (incrementalDataRecord.label != null) {
|
|
1422
|
+
incrementalResult.label = incrementalDataRecord.label;
|
|
1423
|
+
}
|
|
1424
|
+
if (incrementalDataRecord.errors.length > 0) {
|
|
1425
|
+
incrementalResult.errors = incrementalDataRecord.errors;
|
|
1426
|
+
}
|
|
1427
|
+
incrementalResults.push(incrementalResult);
|
|
1428
|
+
}
|
|
1429
|
+
return incrementalResults;
|
|
1430
|
+
}
|
|
1431
|
+
function yieldSubsequentPayloads(exeContext) {
|
|
1432
|
+
let isDone = false;
|
|
1433
|
+
function next() {
|
|
1434
|
+
return __async(this, null, function* () {
|
|
1435
|
+
if (isDone) {
|
|
1436
|
+
return { value: void 0, done: true };
|
|
1437
|
+
}
|
|
1438
|
+
yield Promise.race(
|
|
1439
|
+
Array.from(exeContext.subsequentPayloads).map((p) => p.promise)
|
|
1440
|
+
);
|
|
1441
|
+
if (isDone) {
|
|
1442
|
+
return { value: void 0, done: true };
|
|
1443
|
+
}
|
|
1444
|
+
const incremental = getCompletedIncrementalResults(exeContext);
|
|
1445
|
+
const hasNext = exeContext.subsequentPayloads.size > 0;
|
|
1446
|
+
if (!incremental.length && hasNext) {
|
|
1447
|
+
return next();
|
|
1448
|
+
}
|
|
1449
|
+
if (!hasNext) {
|
|
1450
|
+
isDone = true;
|
|
1451
|
+
}
|
|
1452
|
+
return {
|
|
1453
|
+
value: incremental.length ? { incremental, hasNext } : { hasNext },
|
|
1454
|
+
done: false
|
|
1455
|
+
};
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
function returnStreamIterators() {
|
|
1459
|
+
const promises = [];
|
|
1460
|
+
exeContext.subsequentPayloads.forEach((incrementalDataRecord) => {
|
|
1461
|
+
var _a2;
|
|
1462
|
+
if (isStreamItemsRecord(incrementalDataRecord) && ((_a2 = incrementalDataRecord.asyncIterator) == null ? void 0 : _a2.return)) {
|
|
1463
|
+
promises.push(incrementalDataRecord.asyncIterator.return());
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
return Promise.all(promises);
|
|
1467
|
+
}
|
|
1468
|
+
return {
|
|
1469
|
+
[Symbol.asyncIterator]() {
|
|
1470
|
+
return this;
|
|
1471
|
+
},
|
|
1472
|
+
next,
|
|
1473
|
+
return() {
|
|
1474
|
+
return __async(this, null, function* () {
|
|
1475
|
+
yield returnStreamIterators();
|
|
1476
|
+
isDone = true;
|
|
1477
|
+
return { value: void 0, done: true };
|
|
1478
|
+
});
|
|
1479
|
+
},
|
|
1480
|
+
throw(error) {
|
|
1481
|
+
return __async(this, null, function* () {
|
|
1482
|
+
yield returnStreamIterators();
|
|
1483
|
+
isDone = true;
|
|
1484
|
+
return Promise.reject(error);
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
function isStreamItemsRecord(incrementalDataRecord) {
|
|
1490
|
+
return incrementalDataRecord.type === "stream";
|
|
1491
|
+
}
|
|
1492
|
+
var DeferredFragmentRecord = class {
|
|
1493
|
+
constructor(opts) {
|
|
1494
|
+
this.type = "defer";
|
|
1495
|
+
this.label = opts.label;
|
|
1496
|
+
this.path = pathToArray(opts.path);
|
|
1497
|
+
this.parentContext = opts.parentContext;
|
|
1498
|
+
this.errors = [];
|
|
1499
|
+
this._exeContext = opts.exeContext;
|
|
1500
|
+
this._exeContext.subsequentPayloads.add(this);
|
|
1501
|
+
this.isCompleted = false;
|
|
1502
|
+
this.data = null;
|
|
1503
|
+
this.promise = new Promise((resolve) => {
|
|
1504
|
+
this._resolve = (promiseOrValue) => {
|
|
1505
|
+
resolve(promiseOrValue);
|
|
1506
|
+
};
|
|
1507
|
+
}).then((data) => {
|
|
1508
|
+
this.data = data;
|
|
1509
|
+
this.isCompleted = true;
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
addData(data) {
|
|
1513
|
+
var _a, _b, _c;
|
|
1514
|
+
const parentData = (_a = this.parentContext) == null ? void 0 : _a.promise;
|
|
1515
|
+
if (parentData) {
|
|
1516
|
+
(_b = this._resolve) == null ? void 0 : _b.call(this, parentData.then(() => data));
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
(_c = this._resolve) == null ? void 0 : _c.call(this, data);
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
var StreamItemsRecord = class {
|
|
1523
|
+
constructor(opts) {
|
|
1524
|
+
this.type = "stream";
|
|
1525
|
+
this.items = null;
|
|
1526
|
+
this.label = opts.label;
|
|
1527
|
+
this.path = pathToArray(opts.path);
|
|
1528
|
+
this.parentContext = opts.parentContext;
|
|
1529
|
+
this.asyncIterator = opts.asyncIterator;
|
|
1530
|
+
this.errors = [];
|
|
1531
|
+
this._exeContext = opts.exeContext;
|
|
1532
|
+
this._exeContext.subsequentPayloads.add(this);
|
|
1533
|
+
this.isCompleted = false;
|
|
1534
|
+
this.items = null;
|
|
1535
|
+
this.promise = new Promise((resolve) => {
|
|
1536
|
+
this._resolve = (promiseOrValue) => {
|
|
1537
|
+
resolve(promiseOrValue);
|
|
1538
|
+
};
|
|
1539
|
+
}).then((items) => {
|
|
1540
|
+
this.items = items;
|
|
1541
|
+
this.isCompleted = true;
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
addItems(items) {
|
|
1545
|
+
var _a, _b, _c;
|
|
1546
|
+
const parentData = (_a = this.parentContext) == null ? void 0 : _a.promise;
|
|
1547
|
+
if (parentData) {
|
|
1548
|
+
(_b = this._resolve) == null ? void 0 : _b.call(this, parentData.then(() => items));
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
(_c = this._resolve) == null ? void 0 : _c.call(this, items);
|
|
1552
|
+
}
|
|
1553
|
+
setIsCompletedAsyncIterator() {
|
|
1554
|
+
this.isCompletedAsyncIterator = true;
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
693
1557
|
export {
|
|
694
1558
|
assertValidExecutionArguments,
|
|
695
|
-
buildExecutionContext,
|
|
696
1559
|
buildResolveInfo,
|
|
697
1560
|
defaultFieldResolver,
|
|
698
1561
|
defaultTypeResolver,
|