@graphitation/supermassive 3.2.7 → 3.3.0
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 +10 -2
- package/lib/IncrementalPublisher.d.ts +131 -0
- package/lib/IncrementalPublisher.d.ts.map +1 -0
- package/lib/IncrementalPublisher.js +519 -0
- package/lib/IncrementalPublisher.js.map +7 -0
- package/lib/IncrementalPublisher.mjs +503 -0
- package/lib/IncrementalPublisher.mjs.map +7 -0
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +25 -0
- package/lib/benchmarks/swapi-schema/resolvers.js.map +2 -2
- package/lib/benchmarks/swapi-schema/resolvers.mjs +25 -0
- package/lib/benchmarks/swapi-schema/resolvers.mjs.map +2 -2
- package/lib/buildFieldPlan.d.ts +18 -0
- package/lib/buildFieldPlan.d.ts.map +1 -0
- package/lib/buildFieldPlan.js +120 -0
- package/lib/buildFieldPlan.js.map +7 -0
- package/lib/buildFieldPlan.mjs +101 -0
- package/lib/buildFieldPlan.mjs.map +7 -0
- package/lib/collectFields.d.ts +21 -8
- package/lib/collectFields.d.ts.map +1 -1
- package/lib/collectFields.js +97 -95
- package/lib/collectFields.js.map +2 -2
- package/lib/collectFields.mjs +97 -95
- package/lib/collectFields.mjs.map +2 -2
- package/lib/executeWithoutSchema.d.ts +6 -50
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +603 -485
- package/lib/executeWithoutSchema.js.map +3 -3
- package/lib/executeWithoutSchema.mjs +614 -486
- package/lib/executeWithoutSchema.mjs.map +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/jsutils/getBySet.d.ts +2 -0
- package/lib/jsutils/getBySet.d.ts.map +1 -0
- package/lib/jsutils/getBySet.js +32 -0
- package/lib/jsutils/getBySet.js.map +7 -0
- package/lib/jsutils/getBySet.mjs +13 -0
- package/lib/jsutils/getBySet.mjs.map +7 -0
- package/lib/jsutils/isSameSet.d.ts +2 -0
- package/lib/jsutils/isSameSet.d.ts.map +1 -0
- package/lib/jsutils/isSameSet.js +34 -0
- package/lib/jsutils/isSameSet.js.map +7 -0
- package/lib/jsutils/isSameSet.mjs +15 -0
- package/lib/jsutils/isSameSet.mjs.map +7 -0
- package/lib/jsutils/promiseWithResolvers.d.ts +11 -0
- package/lib/jsutils/promiseWithResolvers.d.ts.map +1 -0
- package/lib/jsutils/promiseWithResolvers.js +32 -0
- package/lib/jsutils/promiseWithResolvers.js.map +7 -0
- package/lib/jsutils/promiseWithResolvers.mjs +13 -0
- package/lib/jsutils/promiseWithResolvers.mjs.map +7 -0
- package/lib/types.d.ts +63 -27
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/values.d.ts +5 -4
- package/lib/values.d.ts.map +1 -1
- package/lib/values.js +13 -8
- package/lib/values.js.map +2 -2
- package/lib/values.mjs +13 -8
- package/lib/values.mjs.map +2 -2
- package/package.json +1 -1
|
@@ -40,12 +40,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
|
|
41
41
|
// src/executeWithoutSchema.ts
|
|
42
42
|
import {
|
|
43
|
+
GraphQLError,
|
|
43
44
|
Kind,
|
|
44
45
|
locatedError
|
|
45
46
|
} from "graphql";
|
|
46
47
|
import {
|
|
47
48
|
collectFields,
|
|
48
|
-
collectSubfields
|
|
49
|
+
collectSubfields
|
|
49
50
|
} from "./collectFields.mjs";
|
|
50
51
|
import { devAssert } from "./jsutils/devAssert.mjs";
|
|
51
52
|
import { inspect } from "./jsutils/inspect.mjs";
|
|
@@ -75,15 +76,40 @@ import {
|
|
|
75
76
|
} from "./schema/reference.mjs";
|
|
76
77
|
import * as Definitions from "./schema/definition.mjs";
|
|
77
78
|
import * as Resolvers from "./schema/resolvers.mjs";
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
import {
|
|
80
|
+
buildFieldPlan
|
|
81
|
+
} from "./buildFieldPlan.mjs";
|
|
82
|
+
import {
|
|
83
|
+
DeferredFragmentRecord,
|
|
84
|
+
DeferredGroupedFieldSetRecord,
|
|
85
|
+
IncrementalPublisher,
|
|
86
|
+
InitialResultRecord,
|
|
87
|
+
StreamItemsRecord,
|
|
88
|
+
StreamRecord
|
|
89
|
+
} from "./IncrementalPublisher.mjs";
|
|
90
|
+
var buildSubFieldPlan = memoize3(
|
|
91
|
+
(exeContext, returnTypeName, fieldGroup) => {
|
|
92
|
+
const subFields = collectSubfields(
|
|
93
|
+
exeContext.schemaFragment,
|
|
94
|
+
exeContext.fragments,
|
|
95
|
+
exeContext.variableValues,
|
|
96
|
+
exeContext.operation,
|
|
97
|
+
returnTypeName.name,
|
|
98
|
+
fieldGroup.fields
|
|
99
|
+
);
|
|
100
|
+
return buildFieldPlan(
|
|
101
|
+
subFields,
|
|
102
|
+
fieldGroup.deferUsages,
|
|
103
|
+
fieldGroup.knownDeferUsages
|
|
104
|
+
);
|
|
105
|
+
}
|
|
80
106
|
);
|
|
81
107
|
function executeWithoutSchema(args) {
|
|
82
108
|
const exeContext = buildExecutionContext(args);
|
|
83
109
|
if (!("schemaFragment" in exeContext)) {
|
|
84
110
|
return { errors: exeContext };
|
|
85
111
|
} else {
|
|
86
|
-
return
|
|
112
|
+
return executeImpl(exeContext);
|
|
87
113
|
}
|
|
88
114
|
}
|
|
89
115
|
function assertValidExecutionArguments(document, rawVariableValues) {
|
|
@@ -162,24 +188,75 @@ function buildExecutionContext(args) {
|
|
|
162
188
|
fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
|
|
163
189
|
typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
|
|
164
190
|
subscribeFieldResolver: subscribeFieldResolver != null ? subscribeFieldResolver : defaultFieldResolver,
|
|
165
|
-
errors: [],
|
|
166
191
|
fieldExecutionHooks,
|
|
167
|
-
|
|
192
|
+
incrementalPublisher: new IncrementalPublisher()
|
|
168
193
|
};
|
|
169
194
|
}
|
|
170
195
|
function buildPerEventExecutionContext(exeContext, payload) {
|
|
171
196
|
return __spreadProps(__spreadValues({}, exeContext), {
|
|
172
197
|
contextValue: exeContext.buildContextValue ? exeContext.buildContextValue(exeContext.contextValue) : exeContext.contextValue,
|
|
173
|
-
rootValue: payload
|
|
174
|
-
subsequentPayloads: /* @__PURE__ */ new Set(),
|
|
175
|
-
errors: []
|
|
198
|
+
rootValue: payload
|
|
176
199
|
});
|
|
177
200
|
}
|
|
178
|
-
function
|
|
179
|
-
const
|
|
201
|
+
function executeImpl(exeContext) {
|
|
202
|
+
const incrementalPublisher = exeContext.incrementalPublisher;
|
|
203
|
+
const initialResultRecord = new InitialResultRecord();
|
|
204
|
+
try {
|
|
205
|
+
const data = executeOperation(exeContext, initialResultRecord);
|
|
206
|
+
if (isPromise(data)) {
|
|
207
|
+
return data.then(
|
|
208
|
+
(resolved) => {
|
|
209
|
+
if (isAsyncIterable(resolved)) {
|
|
210
|
+
return resolved;
|
|
211
|
+
} else {
|
|
212
|
+
return incrementalPublisher.buildDataResponse(
|
|
213
|
+
initialResultRecord,
|
|
214
|
+
resolved
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
(error) => incrementalPublisher.buildErrorResponse(initialResultRecord, error)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
if (isAsyncIterable(data)) {
|
|
222
|
+
return data;
|
|
223
|
+
} else {
|
|
224
|
+
return incrementalPublisher.buildDataResponse(initialResultRecord, data);
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (exeContext.operation.operation === "subscription") {
|
|
228
|
+
return { errors: [error] };
|
|
229
|
+
} else {
|
|
230
|
+
return incrementalPublisher.buildErrorResponse(
|
|
231
|
+
initialResultRecord,
|
|
232
|
+
error
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function executeOperation(exeContext, initialResultRecord) {
|
|
238
|
+
const { operation, rootValue, incrementalPublisher } = exeContext;
|
|
180
239
|
const rootTypeName = getOperationRootTypeName(operation);
|
|
181
|
-
|
|
240
|
+
if (rootTypeName == null) {
|
|
241
|
+
throw new GraphQLError(
|
|
242
|
+
`Schema is not configured to execute ${operation.operation} operation.`,
|
|
243
|
+
operation
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const fields = collectFields(exeContext, rootTypeName);
|
|
247
|
+
const { groupedFieldSet, newGroupedFieldSetDetailsMap, newDeferUsages } = buildFieldPlan(fields);
|
|
248
|
+
const newDeferMap = addNewDeferredFragments(
|
|
249
|
+
incrementalPublisher,
|
|
250
|
+
newDeferUsages,
|
|
251
|
+
initialResultRecord
|
|
252
|
+
);
|
|
182
253
|
const path = void 0;
|
|
254
|
+
const newDeferredGroupedFieldSetRecords = addNewDeferredGroupedFieldSets(
|
|
255
|
+
incrementalPublisher,
|
|
256
|
+
newGroupedFieldSetDetailsMap,
|
|
257
|
+
newDeferMap,
|
|
258
|
+
path
|
|
259
|
+
);
|
|
183
260
|
let result;
|
|
184
261
|
switch (operation.operation) {
|
|
185
262
|
case "query":
|
|
@@ -189,9 +266,9 @@ function executeOperation(exeContext) {
|
|
|
189
266
|
rootValue,
|
|
190
267
|
path,
|
|
191
268
|
groupedFieldSet,
|
|
192
|
-
|
|
269
|
+
initialResultRecord,
|
|
270
|
+
newDeferMap
|
|
193
271
|
);
|
|
194
|
-
result = buildResponse(exeContext, result);
|
|
195
272
|
break;
|
|
196
273
|
case "mutation":
|
|
197
274
|
result = executeFieldsSerially(
|
|
@@ -199,9 +276,10 @@ function executeOperation(exeContext) {
|
|
|
199
276
|
rootTypeName,
|
|
200
277
|
rootValue,
|
|
201
278
|
path,
|
|
202
|
-
groupedFieldSet
|
|
279
|
+
groupedFieldSet,
|
|
280
|
+
initialResultRecord,
|
|
281
|
+
newDeferMap
|
|
203
282
|
);
|
|
204
|
-
result = buildResponse(exeContext, result);
|
|
205
283
|
break;
|
|
206
284
|
case "subscription": {
|
|
207
285
|
const resultOrStreamOrPromise = createSourceEventStream(exeContext);
|
|
@@ -210,57 +288,26 @@ function executeOperation(exeContext) {
|
|
|
210
288
|
exeContext,
|
|
211
289
|
rootTypeName,
|
|
212
290
|
path,
|
|
213
|
-
groupedFieldSet
|
|
291
|
+
groupedFieldSet,
|
|
292
|
+
initialResultRecord,
|
|
293
|
+
newDeferMap
|
|
214
294
|
);
|
|
215
295
|
break;
|
|
216
296
|
}
|
|
217
|
-
default:
|
|
218
|
-
invariant(
|
|
219
|
-
false,
|
|
220
|
-
`Operation "${operation.operation}" is not a part of GraphQL spec`
|
|
221
|
-
);
|
|
222
297
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
executeDeferredFragment(
|
|
298
|
+
if (operation.operation !== "subscription") {
|
|
299
|
+
executeDeferredGroupedFieldSets(
|
|
226
300
|
exeContext,
|
|
227
301
|
rootTypeName,
|
|
228
302
|
rootValue,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
303
|
+
path,
|
|
304
|
+
newDeferredGroupedFieldSetRecords,
|
|
305
|
+
newDeferMap
|
|
232
306
|
);
|
|
233
307
|
}
|
|
234
308
|
return result;
|
|
235
309
|
}
|
|
236
|
-
function
|
|
237
|
-
if (isPromise(data)) {
|
|
238
|
-
return data.then(
|
|
239
|
-
(resolved) => buildResponse(exeContext, resolved),
|
|
240
|
-
(error) => {
|
|
241
|
-
exeContext.errors.push(error);
|
|
242
|
-
return buildResponse(exeContext, null);
|
|
243
|
-
}
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
try {
|
|
247
|
-
const initialResult = exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
248
|
-
if (exeContext.subsequentPayloads.size > 0) {
|
|
249
|
-
return {
|
|
250
|
-
initialResult: __spreadProps(__spreadValues({}, initialResult), {
|
|
251
|
-
hasNext: true
|
|
252
|
-
}),
|
|
253
|
-
subsequentResults: yieldSubsequentPayloads(exeContext)
|
|
254
|
-
};
|
|
255
|
-
} else {
|
|
256
|
-
return initialResult;
|
|
257
|
-
}
|
|
258
|
-
} catch (error) {
|
|
259
|
-
exeContext.errors.push(error);
|
|
260
|
-
return buildResponse(exeContext, null);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, groupedFieldSet) {
|
|
310
|
+
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, groupedFieldSet, incrementalDataRecord, deferMap) {
|
|
264
311
|
return promiseReduce(
|
|
265
312
|
groupedFieldSet,
|
|
266
313
|
(results, [responseName, fieldGroup]) => {
|
|
@@ -271,7 +318,8 @@ function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, gr
|
|
|
271
318
|
sourceValue,
|
|
272
319
|
fieldGroup,
|
|
273
320
|
fieldPath,
|
|
274
|
-
|
|
321
|
+
incrementalDataRecord,
|
|
322
|
+
deferMap
|
|
275
323
|
);
|
|
276
324
|
if (result === void 0) {
|
|
277
325
|
return results;
|
|
@@ -288,7 +336,7 @@ function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, gr
|
|
|
288
336
|
/* @__PURE__ */ Object.create(null)
|
|
289
337
|
);
|
|
290
338
|
}
|
|
291
|
-
function executeFields(exeContext, parentTypeName, sourceValue, path, groupedFieldSet, incrementalDataRecord) {
|
|
339
|
+
function executeFields(exeContext, parentTypeName, sourceValue, path, groupedFieldSet, incrementalDataRecord, deferMap) {
|
|
292
340
|
const results = /* @__PURE__ */ Object.create(null);
|
|
293
341
|
let containsPromise = false;
|
|
294
342
|
for (const [responseName, fieldGroup] of groupedFieldSet) {
|
|
@@ -299,7 +347,8 @@ function executeFields(exeContext, parentTypeName, sourceValue, path, groupedFie
|
|
|
299
347
|
sourceValue,
|
|
300
348
|
fieldGroup,
|
|
301
349
|
fieldPath,
|
|
302
|
-
incrementalDataRecord
|
|
350
|
+
incrementalDataRecord,
|
|
351
|
+
deferMap
|
|
303
352
|
);
|
|
304
353
|
if (result !== void 0) {
|
|
305
354
|
results[responseName] = result;
|
|
@@ -313,9 +362,9 @@ function executeFields(exeContext, parentTypeName, sourceValue, path, groupedFie
|
|
|
313
362
|
}
|
|
314
363
|
return promiseForObject(results);
|
|
315
364
|
}
|
|
316
|
-
function executeField(exeContext, parentTypeName, source, fieldGroup, path, incrementalDataRecord) {
|
|
365
|
+
function executeField(exeContext, parentTypeName, source, fieldGroup, path, incrementalDataRecord, deferMap) {
|
|
317
366
|
const schemaFragment = exeContext.schemaFragment;
|
|
318
|
-
const fieldName = fieldGroup[0].name.value;
|
|
367
|
+
const fieldName = fieldGroup.fields[0].node.name.value;
|
|
319
368
|
const fieldDef = Definitions.getField(
|
|
320
369
|
schemaFragment.definitions,
|
|
321
370
|
parentTypeName,
|
|
@@ -329,7 +378,8 @@ function executeField(exeContext, parentTypeName, source, fieldGroup, path, incr
|
|
|
329
378
|
fieldGroup,
|
|
330
379
|
path,
|
|
331
380
|
source,
|
|
332
|
-
incrementalDataRecord
|
|
381
|
+
incrementalDataRecord,
|
|
382
|
+
deferMap
|
|
333
383
|
);
|
|
334
384
|
}
|
|
335
385
|
const loading = requestSchemaFragment(exeContext, {
|
|
@@ -354,7 +404,8 @@ function executeField(exeContext, parentTypeName, source, fieldGroup, path, incr
|
|
|
354
404
|
fieldGroup,
|
|
355
405
|
path,
|
|
356
406
|
source,
|
|
357
|
-
incrementalDataRecord
|
|
407
|
+
incrementalDataRecord,
|
|
408
|
+
deferMap
|
|
358
409
|
);
|
|
359
410
|
}
|
|
360
411
|
return void 0;
|
|
@@ -380,24 +431,16 @@ function requestSchemaFragment(exeContext, request) {
|
|
|
380
431
|
});
|
|
381
432
|
}
|
|
382
433
|
function createSourceEventStream(exeContext) {
|
|
383
|
-
|
|
384
|
-
const eventStream = executeSubscriptionImpl(exeContext);
|
|
385
|
-
if (isPromise(eventStream)) {
|
|
386
|
-
return eventStream.then(void 0, (error) => ({ errors: [error] }));
|
|
387
|
-
}
|
|
388
|
-
return eventStream;
|
|
389
|
-
} catch (error) {
|
|
390
|
-
return { errors: [error] };
|
|
391
|
-
}
|
|
434
|
+
return executeSubscriptionImpl(exeContext);
|
|
392
435
|
}
|
|
393
436
|
function executeSubscriptionImpl(exeContext) {
|
|
394
437
|
var _a;
|
|
395
|
-
const { operation, rootValue
|
|
438
|
+
const { schemaFragment, operation, rootValue } = exeContext;
|
|
396
439
|
const rootTypeName = getOperationRootTypeName(operation);
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
const [responseName, fieldGroup] =
|
|
400
|
-
const fieldName = fieldGroup[0].name.value;
|
|
440
|
+
const fields = collectFields(exeContext, rootTypeName);
|
|
441
|
+
const { groupedFieldSet } = buildFieldPlan(fields);
|
|
442
|
+
const [responseName, fieldGroup] = groupedFieldSet.entries().next().value;
|
|
443
|
+
const fieldName = toNodes(fieldGroup)[0].name.value;
|
|
401
444
|
const fieldDef = Definitions.getField(
|
|
402
445
|
schemaFragment.definitions,
|
|
403
446
|
rootTypeName,
|
|
@@ -406,7 +449,7 @@ function executeSubscriptionImpl(exeContext) {
|
|
|
406
449
|
if (!fieldDef) {
|
|
407
450
|
throw locatedError(
|
|
408
451
|
`The subscription field "${fieldName}" is not defined.`,
|
|
409
|
-
fieldGroup
|
|
452
|
+
toNodes(fieldGroup)
|
|
410
453
|
);
|
|
411
454
|
}
|
|
412
455
|
const returnTypeRef = Definitions.getFieldTypeReference(fieldDef);
|
|
@@ -425,17 +468,22 @@ function executeSubscriptionImpl(exeContext) {
|
|
|
425
468
|
path
|
|
426
469
|
);
|
|
427
470
|
try {
|
|
428
|
-
const args = getArgumentValues(
|
|
471
|
+
const args = getArgumentValues(
|
|
472
|
+
exeContext.schemaFragment,
|
|
473
|
+
fieldDef,
|
|
474
|
+
toNodes(fieldGroup)[0],
|
|
475
|
+
exeContext.variableValues
|
|
476
|
+
);
|
|
429
477
|
const contextValue = exeContext.contextValue;
|
|
430
478
|
const result = resolveFn(rootValue, args, contextValue, info);
|
|
431
479
|
if (isPromise(result)) {
|
|
432
480
|
return result.then(assertEventStream).then(void 0, (error) => {
|
|
433
|
-
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
481
|
+
throw locatedError(error, toNodes(fieldGroup), pathToArray(path));
|
|
434
482
|
});
|
|
435
483
|
}
|
|
436
484
|
return assertEventStream(result);
|
|
437
485
|
} catch (error) {
|
|
438
|
-
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
486
|
+
throw locatedError(error, toNodes(fieldGroup), pathToArray(path));
|
|
439
487
|
}
|
|
440
488
|
}
|
|
441
489
|
function assertEventStream(result) {
|
|
@@ -450,7 +498,7 @@ function assertEventStream(result) {
|
|
|
450
498
|
}
|
|
451
499
|
return result;
|
|
452
500
|
}
|
|
453
|
-
function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, parentTypeName, path, groupedFieldSet) {
|
|
501
|
+
function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, parentTypeName, path, groupedFieldSet, initialResultRecord, deferMap) {
|
|
454
502
|
if (isPromise(resultOrStreamOrPromise)) {
|
|
455
503
|
return resultOrStreamOrPromise.then(
|
|
456
504
|
(resultOrStream) => mapResultOrEventStreamOrPromise(
|
|
@@ -458,7 +506,9 @@ function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, pa
|
|
|
458
506
|
exeContext,
|
|
459
507
|
parentTypeName,
|
|
460
508
|
path,
|
|
461
|
-
groupedFieldSet
|
|
509
|
+
groupedFieldSet,
|
|
510
|
+
initialResultRecord,
|
|
511
|
+
deferMap
|
|
462
512
|
)
|
|
463
513
|
);
|
|
464
514
|
} else {
|
|
@@ -470,15 +520,42 @@ function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, pa
|
|
|
470
520
|
exeContext,
|
|
471
521
|
payload
|
|
472
522
|
);
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
523
|
+
const perEventResultRecord = new InitialResultRecord();
|
|
524
|
+
try {
|
|
525
|
+
const data = executeFields(
|
|
526
|
+
perEventContext,
|
|
527
|
+
parentTypeName,
|
|
528
|
+
payload,
|
|
529
|
+
path,
|
|
530
|
+
groupedFieldSet,
|
|
531
|
+
perEventResultRecord,
|
|
532
|
+
deferMap
|
|
533
|
+
);
|
|
534
|
+
if (isPromise(data)) {
|
|
535
|
+
return data.then(
|
|
536
|
+
(resolved) => {
|
|
537
|
+
return exeContext.incrementalPublisher.buildDataResponse(
|
|
538
|
+
perEventResultRecord,
|
|
539
|
+
resolved
|
|
540
|
+
);
|
|
541
|
+
},
|
|
542
|
+
(error) => exeContext.incrementalPublisher.buildErrorResponse(
|
|
543
|
+
perEventResultRecord,
|
|
544
|
+
error
|
|
545
|
+
)
|
|
546
|
+
);
|
|
547
|
+
} else {
|
|
548
|
+
return exeContext.incrementalPublisher.buildDataResponse(
|
|
549
|
+
perEventResultRecord,
|
|
550
|
+
data
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
} catch (error) {
|
|
554
|
+
return exeContext.incrementalPublisher.buildErrorResponse(
|
|
555
|
+
perEventResultRecord,
|
|
556
|
+
error
|
|
557
|
+
);
|
|
558
|
+
}
|
|
482
559
|
};
|
|
483
560
|
return mapAsyncIterator(resultOrStreamOrPromise, mapSourceToResponse);
|
|
484
561
|
}
|
|
@@ -487,7 +564,7 @@ function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, pa
|
|
|
487
564
|
function buildResolveInfo(exeContext, fieldName, fieldGroup, parentTypeName, returnTypeName, path) {
|
|
488
565
|
return {
|
|
489
566
|
fieldName,
|
|
490
|
-
fieldNodes: fieldGroup,
|
|
567
|
+
fieldNodes: toNodes(fieldGroup),
|
|
491
568
|
returnTypeName,
|
|
492
569
|
parentTypeName,
|
|
493
570
|
path,
|
|
@@ -498,17 +575,15 @@ function buildResolveInfo(exeContext, fieldName, fieldGroup, parentTypeName, ret
|
|
|
498
575
|
};
|
|
499
576
|
}
|
|
500
577
|
function handleFieldError(rawError, exeContext, returnTypeRef, fieldGroup, path, incrementalDataRecord) {
|
|
501
|
-
|
|
502
|
-
const error = locatedError(rawError, fieldGroup, pathToArray(path));
|
|
578
|
+
const error = locatedError(rawError, toNodes(fieldGroup), pathToArray(path));
|
|
503
579
|
if (isNonNullType(returnTypeRef)) {
|
|
504
580
|
throw error;
|
|
505
581
|
}
|
|
506
|
-
|
|
507
|
-
errors.push(error);
|
|
582
|
+
exeContext.incrementalPublisher.addFieldError(incrementalDataRecord, error);
|
|
508
583
|
}
|
|
509
|
-
function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fieldGroup, path, source, incrementalDataRecord) {
|
|
584
|
+
function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fieldGroup, path, source, incrementalDataRecord, deferMap) {
|
|
510
585
|
var _a;
|
|
511
|
-
const fieldName = fieldGroup[0].name.value;
|
|
586
|
+
const fieldName = fieldGroup.fields[0].node.name.value;
|
|
512
587
|
const returnTypeRef = Definitions.getFieldTypeReference(fieldDefinition);
|
|
513
588
|
const resolveFn = (_a = Resolvers.getFieldResolver(
|
|
514
589
|
exeContext.schemaFragment,
|
|
@@ -526,10 +601,15 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
526
601
|
const isDefaultResolverUsed = resolveFn === exeContext.fieldResolver;
|
|
527
602
|
const hooks = exeContext.fieldExecutionHooks;
|
|
528
603
|
try {
|
|
529
|
-
const args = getArgumentValues(
|
|
604
|
+
const args = getArgumentValues(
|
|
605
|
+
exeContext.schemaFragment,
|
|
606
|
+
fieldDefinition,
|
|
607
|
+
fieldGroup.fields[0].node,
|
|
608
|
+
exeContext.variableValues
|
|
609
|
+
);
|
|
530
610
|
const contextValue = exeContext.contextValue;
|
|
531
611
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
532
|
-
invokeBeforeFieldResolveHook(info, exeContext);
|
|
612
|
+
invokeBeforeFieldResolveHook(info, exeContext, incrementalDataRecord);
|
|
533
613
|
}
|
|
534
614
|
const result = resolveFn(source, args, contextValue, info);
|
|
535
615
|
let completed;
|
|
@@ -537,7 +617,12 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
537
617
|
completed = result.then(
|
|
538
618
|
(resolved) => {
|
|
539
619
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
540
|
-
invokeAfterFieldResolveHook(
|
|
620
|
+
invokeAfterFieldResolveHook(
|
|
621
|
+
info,
|
|
622
|
+
exeContext,
|
|
623
|
+
incrementalDataRecord,
|
|
624
|
+
resolved
|
|
625
|
+
);
|
|
541
626
|
}
|
|
542
627
|
return completeValue(
|
|
543
628
|
exeContext,
|
|
@@ -546,19 +631,31 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
546
631
|
info,
|
|
547
632
|
path,
|
|
548
633
|
resolved,
|
|
549
|
-
incrementalDataRecord
|
|
634
|
+
incrementalDataRecord,
|
|
635
|
+
deferMap
|
|
550
636
|
);
|
|
551
637
|
},
|
|
552
638
|
(rawError) => {
|
|
553
639
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
554
|
-
invokeAfterFieldResolveHook(
|
|
640
|
+
invokeAfterFieldResolveHook(
|
|
641
|
+
info,
|
|
642
|
+
exeContext,
|
|
643
|
+
incrementalDataRecord,
|
|
644
|
+
void 0,
|
|
645
|
+
rawError
|
|
646
|
+
);
|
|
555
647
|
}
|
|
556
648
|
throw rawError;
|
|
557
649
|
}
|
|
558
650
|
);
|
|
559
651
|
} else {
|
|
560
652
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
561
|
-
invokeAfterFieldResolveHook(
|
|
653
|
+
invokeAfterFieldResolveHook(
|
|
654
|
+
info,
|
|
655
|
+
exeContext,
|
|
656
|
+
incrementalDataRecord,
|
|
657
|
+
result
|
|
658
|
+
);
|
|
562
659
|
}
|
|
563
660
|
completed = completeValue(
|
|
564
661
|
exeContext,
|
|
@@ -567,21 +664,37 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
567
664
|
info,
|
|
568
665
|
path,
|
|
569
666
|
result,
|
|
570
|
-
incrementalDataRecord
|
|
667
|
+
incrementalDataRecord,
|
|
668
|
+
deferMap
|
|
571
669
|
);
|
|
572
670
|
}
|
|
573
671
|
if (isPromise(completed)) {
|
|
574
672
|
return completed.then(
|
|
575
673
|
(resolved) => {
|
|
576
674
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
577
|
-
invokeAfterFieldCompleteHook(
|
|
675
|
+
invokeAfterFieldCompleteHook(
|
|
676
|
+
info,
|
|
677
|
+
exeContext,
|
|
678
|
+
incrementalDataRecord,
|
|
679
|
+
resolved
|
|
680
|
+
);
|
|
578
681
|
}
|
|
579
682
|
return resolved;
|
|
580
683
|
},
|
|
581
684
|
(rawError) => {
|
|
582
|
-
const error = locatedError(
|
|
685
|
+
const error = locatedError(
|
|
686
|
+
rawError,
|
|
687
|
+
toNodes(fieldGroup),
|
|
688
|
+
pathToArray(path)
|
|
689
|
+
);
|
|
583
690
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
584
|
-
invokeAfterFieldCompleteHook(
|
|
691
|
+
invokeAfterFieldCompleteHook(
|
|
692
|
+
info,
|
|
693
|
+
exeContext,
|
|
694
|
+
incrementalDataRecord,
|
|
695
|
+
void 0,
|
|
696
|
+
error
|
|
697
|
+
);
|
|
585
698
|
}
|
|
586
699
|
handleFieldError(
|
|
587
700
|
rawError,
|
|
@@ -596,17 +709,34 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
596
709
|
);
|
|
597
710
|
}
|
|
598
711
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
599
|
-
invokeAfterFieldCompleteHook(
|
|
712
|
+
invokeAfterFieldCompleteHook(
|
|
713
|
+
info,
|
|
714
|
+
exeContext,
|
|
715
|
+
incrementalDataRecord,
|
|
716
|
+
completed
|
|
717
|
+
);
|
|
600
718
|
}
|
|
601
719
|
return completed;
|
|
602
720
|
} catch (rawError) {
|
|
603
721
|
const pathArray = pathToArray(path);
|
|
604
|
-
const error = locatedError(rawError, fieldGroup, pathArray);
|
|
722
|
+
const error = locatedError(rawError, fieldGroup.fields[0].node, pathArray);
|
|
605
723
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve) && error.path && arraysAreEqual(pathArray, error.path)) {
|
|
606
|
-
invokeAfterFieldResolveHook(
|
|
724
|
+
invokeAfterFieldResolveHook(
|
|
725
|
+
info,
|
|
726
|
+
exeContext,
|
|
727
|
+
incrementalDataRecord,
|
|
728
|
+
void 0,
|
|
729
|
+
error
|
|
730
|
+
);
|
|
607
731
|
}
|
|
608
732
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
609
|
-
invokeAfterFieldCompleteHook(
|
|
733
|
+
invokeAfterFieldCompleteHook(
|
|
734
|
+
info,
|
|
735
|
+
exeContext,
|
|
736
|
+
incrementalDataRecord,
|
|
737
|
+
void 0,
|
|
738
|
+
error
|
|
739
|
+
);
|
|
610
740
|
}
|
|
611
741
|
handleFieldError(
|
|
612
742
|
rawError,
|
|
@@ -619,7 +749,7 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
619
749
|
return null;
|
|
620
750
|
}
|
|
621
751
|
}
|
|
622
|
-
function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
752
|
+
function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord, deferMap) {
|
|
623
753
|
if (result instanceof Error) {
|
|
624
754
|
throw result;
|
|
625
755
|
}
|
|
@@ -631,7 +761,8 @@ function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result
|
|
|
631
761
|
info,
|
|
632
762
|
path,
|
|
633
763
|
result,
|
|
634
|
-
incrementalDataRecord
|
|
764
|
+
incrementalDataRecord,
|
|
765
|
+
deferMap
|
|
635
766
|
);
|
|
636
767
|
if (completed === null) {
|
|
637
768
|
throw new Error(
|
|
@@ -651,7 +782,8 @@ function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result
|
|
|
651
782
|
info,
|
|
652
783
|
path,
|
|
653
784
|
result,
|
|
654
|
-
incrementalDataRecord
|
|
785
|
+
incrementalDataRecord,
|
|
786
|
+
deferMap
|
|
655
787
|
);
|
|
656
788
|
}
|
|
657
789
|
const { schemaFragment } = exeContext;
|
|
@@ -668,7 +800,8 @@ function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result
|
|
|
668
800
|
info,
|
|
669
801
|
path,
|
|
670
802
|
result,
|
|
671
|
-
incrementalDataRecord
|
|
803
|
+
incrementalDataRecord,
|
|
804
|
+
deferMap
|
|
672
805
|
);
|
|
673
806
|
}
|
|
674
807
|
if (Definitions.isObjectType(schemaFragment.definitions, returnTypeRef)) {
|
|
@@ -678,7 +811,8 @@ function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result
|
|
|
678
811
|
fieldGroup,
|
|
679
812
|
path,
|
|
680
813
|
result,
|
|
681
|
-
incrementalDataRecord
|
|
814
|
+
incrementalDataRecord,
|
|
815
|
+
deferMap
|
|
682
816
|
);
|
|
683
817
|
}
|
|
684
818
|
invariant(
|
|
@@ -686,7 +820,7 @@ function completeValue(exeContext, returnTypeRef, fieldGroup, info, path, result
|
|
|
686
820
|
"Cannot complete value of unexpected output type: " + inspectTypeReference(returnTypeRef)
|
|
687
821
|
);
|
|
688
822
|
}
|
|
689
|
-
function completePromisedValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
823
|
+
function completePromisedValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord, deferMap) {
|
|
690
824
|
return __async(this, null, function* () {
|
|
691
825
|
try {
|
|
692
826
|
const resolved = yield result;
|
|
@@ -697,7 +831,8 @@ function completePromisedValue(exeContext, returnTypeRef, fieldGroup, info, path
|
|
|
697
831
|
info,
|
|
698
832
|
path,
|
|
699
833
|
resolved,
|
|
700
|
-
incrementalDataRecord
|
|
834
|
+
incrementalDataRecord,
|
|
835
|
+
deferMap
|
|
701
836
|
);
|
|
702
837
|
if (isPromise(completed)) {
|
|
703
838
|
completed = yield completed;
|
|
@@ -712,12 +847,12 @@ function completePromisedValue(exeContext, returnTypeRef, fieldGroup, info, path
|
|
|
712
847
|
path,
|
|
713
848
|
incrementalDataRecord
|
|
714
849
|
);
|
|
715
|
-
|
|
850
|
+
exeContext.incrementalPublisher.filter(path, incrementalDataRecord);
|
|
716
851
|
return null;
|
|
717
852
|
}
|
|
718
853
|
});
|
|
719
854
|
}
|
|
720
|
-
function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
855
|
+
function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, result, incrementalDataRecord, deferMap) {
|
|
721
856
|
const itemTypeRef = unwrap(returnTypeRef);
|
|
722
857
|
if (isAsyncIterable(result)) {
|
|
723
858
|
const asyncIterator = result[Symbol.asyncIterator]();
|
|
@@ -728,7 +863,8 @@ function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, re
|
|
|
728
863
|
info,
|
|
729
864
|
path,
|
|
730
865
|
asyncIterator,
|
|
731
|
-
incrementalDataRecord
|
|
866
|
+
incrementalDataRecord,
|
|
867
|
+
deferMap
|
|
732
868
|
);
|
|
733
869
|
}
|
|
734
870
|
if (!isIterableObject(result)) {
|
|
@@ -737,24 +873,28 @@ function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, re
|
|
|
737
873
|
[]
|
|
738
874
|
);
|
|
739
875
|
}
|
|
740
|
-
const
|
|
876
|
+
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
|
|
741
877
|
let containsPromise = false;
|
|
742
|
-
let
|
|
878
|
+
let currentParents = incrementalDataRecord;
|
|
743
879
|
const completedResults = [];
|
|
744
880
|
let index = 0;
|
|
881
|
+
let streamRecord;
|
|
745
882
|
for (const item of result) {
|
|
746
883
|
const itemPath = addPath(path, index, void 0);
|
|
747
|
-
if (
|
|
748
|
-
|
|
884
|
+
if (streamUsage && index >= streamUsage.initialCount) {
|
|
885
|
+
if (streamRecord === void 0) {
|
|
886
|
+
streamRecord = new StreamRecord({ label: streamUsage.label, path });
|
|
887
|
+
}
|
|
888
|
+
currentParents = executeStreamField(
|
|
749
889
|
path,
|
|
750
890
|
itemPath,
|
|
751
891
|
item,
|
|
752
892
|
exeContext,
|
|
753
|
-
fieldGroup,
|
|
893
|
+
streamUsage.fieldGroup,
|
|
754
894
|
info,
|
|
755
895
|
itemTypeRef,
|
|
756
|
-
|
|
757
|
-
|
|
896
|
+
currentParents,
|
|
897
|
+
streamRecord
|
|
758
898
|
);
|
|
759
899
|
index++;
|
|
760
900
|
continue;
|
|
@@ -767,7 +907,8 @@ function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, re
|
|
|
767
907
|
fieldGroup,
|
|
768
908
|
info,
|
|
769
909
|
itemPath,
|
|
770
|
-
incrementalDataRecord
|
|
910
|
+
incrementalDataRecord,
|
|
911
|
+
deferMap
|
|
771
912
|
)) {
|
|
772
913
|
containsPromise = true;
|
|
773
914
|
}
|
|
@@ -775,7 +916,52 @@ function completeListValue(exeContext, returnTypeRef, fieldGroup, info, path, re
|
|
|
775
916
|
}
|
|
776
917
|
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
777
918
|
}
|
|
778
|
-
function
|
|
919
|
+
function getStreamUsage(exeContext, fieldGroup, path) {
|
|
920
|
+
if (typeof path.key === "number") {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (fieldGroup._streamUsage !== void 0) {
|
|
924
|
+
return fieldGroup._streamUsage;
|
|
925
|
+
}
|
|
926
|
+
const stream = getDirectiveValues(
|
|
927
|
+
exeContext.schemaFragment,
|
|
928
|
+
GraphQLStreamDirective,
|
|
929
|
+
fieldGroup.fields[0].node,
|
|
930
|
+
exeContext.variableValues
|
|
931
|
+
);
|
|
932
|
+
if (!stream) {
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (stream.if === false) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
invariant(
|
|
939
|
+
typeof stream.initialCount === "number",
|
|
940
|
+
"initialCount must be a number"
|
|
941
|
+
);
|
|
942
|
+
invariant(
|
|
943
|
+
stream.initialCount >= 0,
|
|
944
|
+
"initialCount must be a positive integer"
|
|
945
|
+
);
|
|
946
|
+
invariant(
|
|
947
|
+
exeContext.operation.operation !== "subscription",
|
|
948
|
+
"`@stream` directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`."
|
|
949
|
+
);
|
|
950
|
+
const streamedFieldGroup = {
|
|
951
|
+
fields: fieldGroup.fields.map((fieldDetails) => ({
|
|
952
|
+
node: fieldDetails.node,
|
|
953
|
+
deferUsage: void 0
|
|
954
|
+
}))
|
|
955
|
+
};
|
|
956
|
+
const streamUsage = {
|
|
957
|
+
initialCount: stream.initialCount,
|
|
958
|
+
label: typeof stream.label === "string" ? stream.label : void 0,
|
|
959
|
+
fieldGroup: streamedFieldGroup
|
|
960
|
+
};
|
|
961
|
+
fieldGroup._streamUsage = streamUsage;
|
|
962
|
+
return streamUsage;
|
|
963
|
+
}
|
|
964
|
+
function completeListItemValue(item, completedResults, exeContext, itemTypeRef, fieldGroup, info, itemPath, incrementalDataRecord, deferMap) {
|
|
779
965
|
if (isPromise(item)) {
|
|
780
966
|
completedResults.push(
|
|
781
967
|
completePromisedValue(
|
|
@@ -785,7 +971,8 @@ function completeListItemValue(item, completedResults, exeContext, itemTypeRef,
|
|
|
785
971
|
info,
|
|
786
972
|
itemPath,
|
|
787
973
|
item,
|
|
788
|
-
incrementalDataRecord
|
|
974
|
+
incrementalDataRecord,
|
|
975
|
+
deferMap
|
|
789
976
|
)
|
|
790
977
|
);
|
|
791
978
|
return true;
|
|
@@ -798,7 +985,8 @@ function completeListItemValue(item, completedResults, exeContext, itemTypeRef,
|
|
|
798
985
|
info,
|
|
799
986
|
itemPath,
|
|
800
987
|
item,
|
|
801
|
-
incrementalDataRecord
|
|
988
|
+
incrementalDataRecord,
|
|
989
|
+
deferMap
|
|
802
990
|
);
|
|
803
991
|
if (isPromise(completedItem)) {
|
|
804
992
|
completedResults.push(
|
|
@@ -811,7 +999,10 @@ function completeListItemValue(item, completedResults, exeContext, itemTypeRef,
|
|
|
811
999
|
itemPath,
|
|
812
1000
|
incrementalDataRecord
|
|
813
1001
|
);
|
|
814
|
-
|
|
1002
|
+
exeContext.incrementalPublisher.filter(
|
|
1003
|
+
itemPath,
|
|
1004
|
+
incrementalDataRecord
|
|
1005
|
+
);
|
|
815
1006
|
return null;
|
|
816
1007
|
})
|
|
817
1008
|
);
|
|
@@ -827,61 +1018,35 @@ function completeListItemValue(item, completedResults, exeContext, itemTypeRef,
|
|
|
827
1018
|
itemPath,
|
|
828
1019
|
incrementalDataRecord
|
|
829
1020
|
);
|
|
830
|
-
|
|
1021
|
+
exeContext.incrementalPublisher.filter(itemPath, incrementalDataRecord);
|
|
831
1022
|
completedResults.push(null);
|
|
832
1023
|
}
|
|
833
1024
|
return false;
|
|
834
1025
|
}
|
|
835
|
-
function
|
|
836
|
-
if (typeof path.key === "number") {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
const stream = getDirectiveValues(
|
|
840
|
-
exeContext,
|
|
841
|
-
GraphQLStreamDirective,
|
|
842
|
-
fieldGroup[0]
|
|
843
|
-
);
|
|
844
|
-
if (!stream) {
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
if (stream.if === false) {
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
invariant(
|
|
851
|
-
typeof stream.initialCount === "number",
|
|
852
|
-
"initialCount must be a number"
|
|
853
|
-
);
|
|
854
|
-
invariant(
|
|
855
|
-
stream.initialCount >= 0,
|
|
856
|
-
"initialCount must be a positive integer"
|
|
857
|
-
);
|
|
858
|
-
invariant(
|
|
859
|
-
exeContext.operation.operation !== "subscription",
|
|
860
|
-
"`@stream` directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`."
|
|
861
|
-
);
|
|
862
|
-
return {
|
|
863
|
-
initialCount: stream.initialCount,
|
|
864
|
-
label: typeof stream.label === "string" ? stream.label : void 0
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
function completeAsyncIteratorValue(exeContext, itemTypeRef, fieldGroup, info, path, asyncIterator, incrementalDataRecord) {
|
|
1026
|
+
function completeAsyncIteratorValue(exeContext, itemTypeRef, fieldGroup, info, path, asyncIterator, incrementalDataRecord, deferMap) {
|
|
868
1027
|
return __async(this, null, function* () {
|
|
869
|
-
const
|
|
1028
|
+
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
|
|
870
1029
|
let containsPromise = false;
|
|
871
1030
|
const completedResults = [];
|
|
872
1031
|
let index = 0;
|
|
873
1032
|
while (true) {
|
|
874
|
-
if (
|
|
1033
|
+
if (streamUsage && index >= streamUsage.initialCount) {
|
|
1034
|
+
const earlyReturn = asyncIterator.return;
|
|
1035
|
+
const streamRecord = new StreamRecord({
|
|
1036
|
+
label: streamUsage.label,
|
|
1037
|
+
path,
|
|
1038
|
+
earlyReturn: earlyReturn === void 0 ? void 0 : earlyReturn.bind(asyncIterator)
|
|
1039
|
+
});
|
|
875
1040
|
executeStreamAsyncIterator(
|
|
876
1041
|
index,
|
|
877
1042
|
asyncIterator,
|
|
878
1043
|
exeContext,
|
|
879
|
-
fieldGroup,
|
|
1044
|
+
streamUsage.fieldGroup,
|
|
880
1045
|
info,
|
|
881
1046
|
itemTypeRef,
|
|
882
1047
|
path,
|
|
883
|
-
|
|
884
|
-
|
|
1048
|
+
incrementalDataRecord,
|
|
1049
|
+
streamRecord
|
|
885
1050
|
);
|
|
886
1051
|
break;
|
|
887
1052
|
}
|
|
@@ -893,7 +1058,7 @@ function completeAsyncIteratorValue(exeContext, itemTypeRef, fieldGroup, info, p
|
|
|
893
1058
|
break;
|
|
894
1059
|
}
|
|
895
1060
|
} catch (rawError) {
|
|
896
|
-
throw locatedError(rawError, fieldGroup, pathToArray(path));
|
|
1061
|
+
throw locatedError(rawError, toNodes(fieldGroup), pathToArray(path));
|
|
897
1062
|
}
|
|
898
1063
|
if (completeListItemValue(
|
|
899
1064
|
iteration.value,
|
|
@@ -903,7 +1068,8 @@ function completeAsyncIteratorValue(exeContext, itemTypeRef, fieldGroup, info, p
|
|
|
903
1068
|
fieldGroup,
|
|
904
1069
|
info,
|
|
905
1070
|
itemPath,
|
|
906
|
-
incrementalDataRecord
|
|
1071
|
+
incrementalDataRecord,
|
|
1072
|
+
deferMap
|
|
907
1073
|
)) {
|
|
908
1074
|
containsPromise = true;
|
|
909
1075
|
}
|
|
@@ -921,7 +1087,7 @@ function completeLeafValue(returnType, result) {
|
|
|
921
1087
|
}
|
|
922
1088
|
return serializedResult;
|
|
923
1089
|
}
|
|
924
|
-
function completeAbstractValue(exeContext, returnTypeName, fieldGroup, info, path, result, incrementalDataRecord) {
|
|
1090
|
+
function completeAbstractValue(exeContext, returnTypeName, fieldGroup, info, path, result, incrementalDataRecord, deferMap) {
|
|
925
1091
|
var _a;
|
|
926
1092
|
const { schemaFragment } = exeContext;
|
|
927
1093
|
const resolveTypeFn = (_a = Resolvers.getAbstractTypeResolver(schemaFragment, returnTypeName)) != null ? _a : exeContext.typeResolver;
|
|
@@ -952,7 +1118,8 @@ function completeAbstractValue(exeContext, returnTypeName, fieldGroup, info, pat
|
|
|
952
1118
|
fieldGroup,
|
|
953
1119
|
path,
|
|
954
1120
|
result,
|
|
955
|
-
incrementalDataRecord
|
|
1121
|
+
incrementalDataRecord,
|
|
1122
|
+
deferMap
|
|
956
1123
|
)
|
|
957
1124
|
);
|
|
958
1125
|
}
|
|
@@ -962,14 +1129,15 @@ function completeAbstractValue(exeContext, returnTypeName, fieldGroup, info, pat
|
|
|
962
1129
|
fieldGroup,
|
|
963
1130
|
path,
|
|
964
1131
|
result,
|
|
965
|
-
incrementalDataRecord
|
|
1132
|
+
incrementalDataRecord,
|
|
1133
|
+
deferMap
|
|
966
1134
|
);
|
|
967
1135
|
}
|
|
968
1136
|
function ensureValidRuntimeType(runtimeTypeName, exeContext, returnTypeName, fieldGroup, info, result) {
|
|
969
1137
|
if (runtimeTypeName == null) {
|
|
970
1138
|
throw locatedError(
|
|
971
1139
|
`Abstract type "${returnTypeName}" must resolve to an Object type at runtime for field "${info.parentTypeName}.${info.fieldName}". Either the "${returnTypeName}" should provide a "__resolveType" resolver function or "${info.parentTypeName}.${info.fieldName}" should be an object with "__typename" property.`,
|
|
972
|
-
fieldGroup
|
|
1140
|
+
toNodes(fieldGroup)
|
|
973
1141
|
);
|
|
974
1142
|
}
|
|
975
1143
|
if (typeof runtimeTypeName !== "string") {
|
|
@@ -1011,19 +1179,19 @@ function ensureValidRuntimeTypeImpl(runtimeTypeName, exeContext, returnTypeName,
|
|
|
1011
1179
|
if (!Definitions.isDefined(definitions, runtimeTypeName)) {
|
|
1012
1180
|
throw locatedError(
|
|
1013
1181
|
`Abstract type "${returnTypeName}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
|
|
1014
|
-
fieldGroup
|
|
1182
|
+
toNodes(fieldGroup)
|
|
1015
1183
|
);
|
|
1016
1184
|
}
|
|
1017
1185
|
if (!Definitions.isObjectType(definitions, runtimeTypeName)) {
|
|
1018
1186
|
throw locatedError(
|
|
1019
1187
|
`Abstract type "${returnTypeName}" was resolved to a non-object type "${runtimeTypeName}".`,
|
|
1020
|
-
fieldGroup
|
|
1188
|
+
toNodes(fieldGroup)
|
|
1021
1189
|
);
|
|
1022
1190
|
}
|
|
1023
1191
|
if (!Definitions.isSubType(definitions, returnTypeName, runtimeTypeName)) {
|
|
1024
1192
|
throw locatedError(
|
|
1025
1193
|
`Runtime Object type "${runtimeTypeName}" is not a possible type for "${returnTypeName}".`,
|
|
1026
|
-
fieldGroup
|
|
1194
|
+
toNodes(fieldGroup)
|
|
1027
1195
|
);
|
|
1028
1196
|
}
|
|
1029
1197
|
return runtimeTypeName;
|
|
@@ -1033,7 +1201,7 @@ function ensureValidRuntimeTypeImpl(runtimeTypeName, exeContext, returnTypeName,
|
|
|
1033
1201
|
if (Definitions.isDefined(definitions, runtimeTypeName) && !Definitions.isObjectType(definitions, runtimeTypeName)) {
|
|
1034
1202
|
throw locatedError(
|
|
1035
1203
|
`Abstract type "${returnTypeName}" was resolved to a non-object type "${runtimeTypeName}".`,
|
|
1036
|
-
fieldGroup
|
|
1204
|
+
toNodes(fieldGroup)
|
|
1037
1205
|
);
|
|
1038
1206
|
}
|
|
1039
1207
|
Definitions.addInterfaceImplementation(
|
|
@@ -1045,41 +1213,104 @@ function ensureValidRuntimeTypeImpl(runtimeTypeName, exeContext, returnTypeName,
|
|
|
1045
1213
|
}
|
|
1046
1214
|
invariant(false, `${returnTypeName} is not an abstract type`);
|
|
1047
1215
|
}
|
|
1048
|
-
function completeObjectValue(exeContext, returnTypeName, fieldGroup, path, result, incrementalDataRecord) {
|
|
1216
|
+
function completeObjectValue(exeContext, returnTypeName, fieldGroup, path, result, incrementalDataRecord, deferMap) {
|
|
1049
1217
|
return collectAndExecuteSubfields(
|
|
1050
1218
|
exeContext,
|
|
1051
1219
|
returnTypeName,
|
|
1052
1220
|
fieldGroup,
|
|
1053
1221
|
path,
|
|
1054
1222
|
result,
|
|
1055
|
-
incrementalDataRecord
|
|
1223
|
+
incrementalDataRecord,
|
|
1224
|
+
deferMap
|
|
1056
1225
|
);
|
|
1057
1226
|
}
|
|
1058
|
-
function
|
|
1059
|
-
|
|
1227
|
+
function addNewDeferredFragments(incrementalPublisher, newDeferUsages, incrementalDataRecord, deferMap, path) {
|
|
1228
|
+
if (newDeferUsages.length === 0) {
|
|
1229
|
+
return deferMap != null ? deferMap : /* @__PURE__ */ new Map();
|
|
1230
|
+
}
|
|
1231
|
+
const newDeferMap = deferMap === void 0 ? /* @__PURE__ */ new Map() : new Map(deferMap);
|
|
1232
|
+
for (const newDeferUsage of newDeferUsages) {
|
|
1233
|
+
const parentDeferUsage = newDeferUsage.parentDeferUsage;
|
|
1234
|
+
const parent = parentDeferUsage === void 0 ? incrementalDataRecord : deferredFragmentRecordFromDeferUsage(parentDeferUsage, newDeferMap);
|
|
1235
|
+
const deferredFragmentRecord = new DeferredFragmentRecord({
|
|
1236
|
+
path,
|
|
1237
|
+
label: newDeferUsage.label
|
|
1238
|
+
});
|
|
1239
|
+
incrementalPublisher.reportNewDeferFragmentRecord(
|
|
1240
|
+
deferredFragmentRecord,
|
|
1241
|
+
parent
|
|
1242
|
+
);
|
|
1243
|
+
newDeferMap.set(newDeferUsage, deferredFragmentRecord);
|
|
1244
|
+
}
|
|
1245
|
+
return newDeferMap;
|
|
1246
|
+
}
|
|
1247
|
+
function deferredFragmentRecordFromDeferUsage(deferUsage, deferMap) {
|
|
1248
|
+
return deferMap.get(deferUsage);
|
|
1249
|
+
}
|
|
1250
|
+
function addNewDeferredGroupedFieldSets(incrementalPublisher, newGroupedFieldSetDetailsMap, deferMap, path) {
|
|
1251
|
+
const newDeferredGroupedFieldSetRecords = [];
|
|
1252
|
+
for (const [
|
|
1253
|
+
deferUsageSet,
|
|
1254
|
+
{ groupedFieldSet, shouldInitiateDefer }
|
|
1255
|
+
] of newGroupedFieldSetDetailsMap) {
|
|
1256
|
+
const deferredFragmentRecords = getDeferredFragmentRecords(
|
|
1257
|
+
deferUsageSet,
|
|
1258
|
+
deferMap
|
|
1259
|
+
);
|
|
1260
|
+
const deferredGroupedFieldSetRecord = new DeferredGroupedFieldSetRecord({
|
|
1261
|
+
path,
|
|
1262
|
+
deferredFragmentRecords,
|
|
1263
|
+
groupedFieldSet,
|
|
1264
|
+
shouldInitiateDefer
|
|
1265
|
+
});
|
|
1266
|
+
incrementalPublisher.reportNewDeferredGroupedFieldSetRecord(
|
|
1267
|
+
deferredGroupedFieldSetRecord
|
|
1268
|
+
);
|
|
1269
|
+
newDeferredGroupedFieldSetRecords.push(deferredGroupedFieldSetRecord);
|
|
1270
|
+
}
|
|
1271
|
+
return newDeferredGroupedFieldSetRecords;
|
|
1272
|
+
}
|
|
1273
|
+
function getDeferredFragmentRecords(deferUsages, deferMap) {
|
|
1274
|
+
return Array.from(deferUsages).map(
|
|
1275
|
+
(deferUsage) => deferredFragmentRecordFromDeferUsage(deferUsage, deferMap)
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
function collectAndExecuteSubfields(exeContext, returnType, fieldGroup, path, result, incrementalDataRecord, deferMap) {
|
|
1279
|
+
const { groupedFieldSet, newGroupedFieldSetDetailsMap, newDeferUsages } = buildSubFieldPlan(exeContext, { name: returnType }, fieldGroup);
|
|
1280
|
+
const incrementalPublisher = exeContext.incrementalPublisher;
|
|
1281
|
+
const newDeferMap = addNewDeferredFragments(
|
|
1282
|
+
incrementalPublisher,
|
|
1283
|
+
newDeferUsages,
|
|
1284
|
+
incrementalDataRecord,
|
|
1285
|
+
deferMap,
|
|
1286
|
+
path
|
|
1287
|
+
);
|
|
1288
|
+
const newDeferredGroupedFieldSetRecords = addNewDeferredGroupedFieldSets(
|
|
1289
|
+
incrementalPublisher,
|
|
1290
|
+
newGroupedFieldSetDetailsMap,
|
|
1291
|
+
newDeferMap,
|
|
1292
|
+
path
|
|
1293
|
+
);
|
|
1060
1294
|
const subFields = executeFields(
|
|
1061
1295
|
exeContext,
|
|
1062
|
-
|
|
1296
|
+
returnType,
|
|
1063
1297
|
result,
|
|
1064
1298
|
path,
|
|
1065
|
-
|
|
1066
|
-
incrementalDataRecord
|
|
1299
|
+
groupedFieldSet,
|
|
1300
|
+
incrementalDataRecord,
|
|
1301
|
+
newDeferMap
|
|
1302
|
+
);
|
|
1303
|
+
executeDeferredGroupedFieldSets(
|
|
1304
|
+
exeContext,
|
|
1305
|
+
returnType,
|
|
1306
|
+
result,
|
|
1307
|
+
path,
|
|
1308
|
+
newDeferredGroupedFieldSetRecords,
|
|
1309
|
+
newDeferMap
|
|
1067
1310
|
);
|
|
1068
|
-
for (const subPatch of subPatches) {
|
|
1069
|
-
const { label, groupedFieldSet: subPatchGroupedFieldSet } = subPatch;
|
|
1070
|
-
executeDeferredFragment(
|
|
1071
|
-
exeContext,
|
|
1072
|
-
returnTypeName,
|
|
1073
|
-
result,
|
|
1074
|
-
subPatchGroupedFieldSet,
|
|
1075
|
-
label,
|
|
1076
|
-
path,
|
|
1077
|
-
incrementalDataRecord
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
1311
|
return subFields;
|
|
1081
1312
|
}
|
|
1082
|
-
function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
1313
|
+
function invokeBeforeFieldResolveHook(resolveInfo, exeContext, incrementalDataRecord) {
|
|
1083
1314
|
var _a;
|
|
1084
1315
|
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeFieldResolve;
|
|
1085
1316
|
if (!hook) {
|
|
@@ -1097,12 +1328,15 @@ function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
|
1097
1328
|
resolveInfo.path,
|
|
1098
1329
|
"Unexpected error in beforeFieldResolve hook"
|
|
1099
1330
|
);
|
|
1100
|
-
exeContext.
|
|
1331
|
+
exeContext.incrementalPublisher.addFieldError(
|
|
1332
|
+
incrementalDataRecord,
|
|
1333
|
+
error
|
|
1334
|
+
);
|
|
1101
1335
|
}
|
|
1102
1336
|
}
|
|
1103
1337
|
);
|
|
1104
1338
|
}
|
|
1105
|
-
function invokeAfterFieldResolveHook(resolveInfo, exeContext, result, error) {
|
|
1339
|
+
function invokeAfterFieldResolveHook(resolveInfo, exeContext, incrementalDataRecord, result, error) {
|
|
1106
1340
|
var _a;
|
|
1107
1341
|
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldResolve;
|
|
1108
1342
|
if (!hook) {
|
|
@@ -1122,12 +1356,15 @@ function invokeAfterFieldResolveHook(resolveInfo, exeContext, result, error) {
|
|
|
1122
1356
|
resolveInfo.path,
|
|
1123
1357
|
"Unexpected error in afterFieldResolve hook"
|
|
1124
1358
|
);
|
|
1125
|
-
exeContext.
|
|
1359
|
+
exeContext.incrementalPublisher.addFieldError(
|
|
1360
|
+
incrementalDataRecord,
|
|
1361
|
+
error2
|
|
1362
|
+
);
|
|
1126
1363
|
}
|
|
1127
1364
|
}
|
|
1128
1365
|
);
|
|
1129
1366
|
}
|
|
1130
|
-
function invokeAfterFieldCompleteHook(resolveInfo, exeContext, result, error) {
|
|
1367
|
+
function invokeAfterFieldCompleteHook(resolveInfo, exeContext, incrementalDataRecord, result, error) {
|
|
1131
1368
|
var _a;
|
|
1132
1369
|
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldComplete;
|
|
1133
1370
|
if (!hook) {
|
|
@@ -1147,7 +1384,10 @@ function invokeAfterFieldCompleteHook(resolveInfo, exeContext, result, error) {
|
|
|
1147
1384
|
resolveInfo.path,
|
|
1148
1385
|
"Unexpected error in afterFieldComplete hook"
|
|
1149
1386
|
);
|
|
1150
|
-
exeContext.
|
|
1387
|
+
exeContext.incrementalPublisher.addFieldError(
|
|
1388
|
+
incrementalDataRecord,
|
|
1389
|
+
error2
|
|
1390
|
+
);
|
|
1151
1391
|
}
|
|
1152
1392
|
}
|
|
1153
1393
|
);
|
|
@@ -1201,153 +1441,215 @@ function getOperationRootTypeName(operation) {
|
|
|
1201
1441
|
);
|
|
1202
1442
|
}
|
|
1203
1443
|
}
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1444
|
+
function isIncrementalExecutionResult(result) {
|
|
1445
|
+
return "initialResult" in result;
|
|
1446
|
+
}
|
|
1447
|
+
function isTotalExecutionResult(result) {
|
|
1448
|
+
return !("initialResult" in result);
|
|
1449
|
+
}
|
|
1450
|
+
function executeDeferredGroupedFieldSets(exeContext, parentTypeName, sourceValue, path, newDeferredGroupedFieldSetRecords, deferMap) {
|
|
1451
|
+
for (const deferredGroupedFieldSetRecord of newDeferredGroupedFieldSetRecords) {
|
|
1452
|
+
if (deferredGroupedFieldSetRecord.shouldInitiateDefer) {
|
|
1453
|
+
Promise.resolve().then(
|
|
1454
|
+
() => executeDeferredGroupedFieldSet(
|
|
1455
|
+
exeContext,
|
|
1456
|
+
parentTypeName,
|
|
1457
|
+
sourceValue,
|
|
1458
|
+
path,
|
|
1459
|
+
deferredGroupedFieldSetRecord,
|
|
1460
|
+
deferMap
|
|
1461
|
+
)
|
|
1462
|
+
);
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
executeDeferredGroupedFieldSet(
|
|
1466
|
+
exeContext,
|
|
1467
|
+
parentTypeName,
|
|
1468
|
+
sourceValue,
|
|
1469
|
+
path,
|
|
1470
|
+
deferredGroupedFieldSetRecord,
|
|
1471
|
+
deferMap
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
function executeDeferredGroupedFieldSet(exeContext, parentTypeName, sourceValue, path, deferredGroupedFieldSetRecord, deferMap) {
|
|
1212
1476
|
try {
|
|
1213
|
-
|
|
1477
|
+
const incrementalResult = executeFields(
|
|
1214
1478
|
exeContext,
|
|
1215
1479
|
parentTypeName,
|
|
1216
1480
|
sourceValue,
|
|
1217
1481
|
path,
|
|
1218
|
-
|
|
1219
|
-
|
|
1482
|
+
deferredGroupedFieldSetRecord.groupedFieldSet,
|
|
1483
|
+
deferredGroupedFieldSetRecord,
|
|
1484
|
+
deferMap
|
|
1220
1485
|
);
|
|
1221
|
-
if (isPromise(
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1486
|
+
if (isPromise(incrementalResult)) {
|
|
1487
|
+
incrementalResult.then(
|
|
1488
|
+
(resolved) => exeContext.incrementalPublisher.completeDeferredGroupedFieldSet(
|
|
1489
|
+
deferredGroupedFieldSetRecord,
|
|
1490
|
+
resolved
|
|
1491
|
+
),
|
|
1492
|
+
(error) => exeContext.incrementalPublisher.markErroredDeferredGroupedFieldSet(
|
|
1493
|
+
deferredGroupedFieldSetRecord,
|
|
1494
|
+
error
|
|
1495
|
+
)
|
|
1496
|
+
);
|
|
1497
|
+
return;
|
|
1226
1498
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1499
|
+
exeContext.incrementalPublisher.completeDeferredGroupedFieldSet(
|
|
1500
|
+
deferredGroupedFieldSetRecord,
|
|
1501
|
+
incrementalResult
|
|
1502
|
+
);
|
|
1503
|
+
} catch (error) {
|
|
1504
|
+
exeContext.incrementalPublisher.markErroredDeferredGroupedFieldSet(
|
|
1505
|
+
deferredGroupedFieldSetRecord,
|
|
1506
|
+
error
|
|
1507
|
+
);
|
|
1230
1508
|
}
|
|
1231
|
-
incrementalDataRecord.addData(promiseOrData);
|
|
1232
1509
|
}
|
|
1233
|
-
function executeStreamField(path, itemPath, item, exeContext, fieldGroup, info,
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
exeContext
|
|
1510
|
+
function executeStreamField(path, itemPath, item, exeContext, fieldGroup, info, returnTypeRef, incrementalDataRecord, streamRecord) {
|
|
1511
|
+
const incrementalPublisher = exeContext.incrementalPublisher;
|
|
1512
|
+
const streamItemsRecord = new StreamItemsRecord({
|
|
1513
|
+
streamRecord,
|
|
1514
|
+
path: itemPath
|
|
1239
1515
|
});
|
|
1516
|
+
incrementalPublisher.reportNewStreamItemsRecord(
|
|
1517
|
+
streamItemsRecord,
|
|
1518
|
+
incrementalDataRecord
|
|
1519
|
+
);
|
|
1240
1520
|
if (isPromise(item)) {
|
|
1241
|
-
|
|
1521
|
+
completePromisedValue(
|
|
1242
1522
|
exeContext,
|
|
1243
|
-
|
|
1523
|
+
returnTypeRef,
|
|
1244
1524
|
fieldGroup,
|
|
1245
1525
|
info,
|
|
1246
1526
|
itemPath,
|
|
1247
1527
|
item,
|
|
1248
|
-
|
|
1528
|
+
streamItemsRecord,
|
|
1529
|
+
/* @__PURE__ */ new Map()
|
|
1249
1530
|
).then(
|
|
1250
|
-
(value) => [
|
|
1531
|
+
(value) => incrementalPublisher.completeStreamItemsRecord(streamItemsRecord, [
|
|
1532
|
+
value
|
|
1533
|
+
]),
|
|
1251
1534
|
(error) => {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1535
|
+
incrementalPublisher.filter(path, streamItemsRecord);
|
|
1536
|
+
incrementalPublisher.markErroredStreamItemsRecord(
|
|
1537
|
+
streamItemsRecord,
|
|
1538
|
+
error
|
|
1539
|
+
);
|
|
1255
1540
|
}
|
|
1256
1541
|
);
|
|
1257
|
-
|
|
1258
|
-
return incrementalDataRecord;
|
|
1542
|
+
return streamItemsRecord;
|
|
1259
1543
|
}
|
|
1260
1544
|
let completedItem;
|
|
1261
1545
|
try {
|
|
1262
1546
|
try {
|
|
1263
1547
|
completedItem = completeValue(
|
|
1264
1548
|
exeContext,
|
|
1265
|
-
|
|
1549
|
+
returnTypeRef,
|
|
1266
1550
|
fieldGroup,
|
|
1267
1551
|
info,
|
|
1268
1552
|
itemPath,
|
|
1269
1553
|
item,
|
|
1270
|
-
|
|
1554
|
+
streamItemsRecord,
|
|
1555
|
+
/* @__PURE__ */ new Map()
|
|
1271
1556
|
);
|
|
1272
1557
|
} catch (rawError) {
|
|
1273
1558
|
handleFieldError(
|
|
1274
1559
|
rawError,
|
|
1275
1560
|
exeContext,
|
|
1276
|
-
|
|
1561
|
+
returnTypeRef,
|
|
1277
1562
|
fieldGroup,
|
|
1278
1563
|
itemPath,
|
|
1279
|
-
|
|
1564
|
+
streamItemsRecord
|
|
1280
1565
|
);
|
|
1281
1566
|
completedItem = null;
|
|
1282
|
-
|
|
1567
|
+
incrementalPublisher.filter(itemPath, streamItemsRecord);
|
|
1283
1568
|
}
|
|
1284
1569
|
} catch (error) {
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1570
|
+
incrementalPublisher.filter(path, streamItemsRecord);
|
|
1571
|
+
incrementalPublisher.markErroredStreamItemsRecord(
|
|
1572
|
+
streamItemsRecord,
|
|
1573
|
+
error
|
|
1574
|
+
);
|
|
1575
|
+
return streamItemsRecord;
|
|
1289
1576
|
}
|
|
1290
1577
|
if (isPromise(completedItem)) {
|
|
1291
|
-
|
|
1578
|
+
completedItem.then(void 0, (rawError) => {
|
|
1292
1579
|
handleFieldError(
|
|
1293
1580
|
rawError,
|
|
1294
1581
|
exeContext,
|
|
1295
|
-
|
|
1582
|
+
returnTypeRef,
|
|
1296
1583
|
fieldGroup,
|
|
1297
1584
|
itemPath,
|
|
1298
|
-
|
|
1585
|
+
streamItemsRecord
|
|
1299
1586
|
);
|
|
1300
|
-
|
|
1587
|
+
incrementalPublisher.filter(itemPath, streamItemsRecord);
|
|
1301
1588
|
return null;
|
|
1302
1589
|
}).then(
|
|
1303
|
-
(value) => [
|
|
1590
|
+
(value) => incrementalPublisher.completeStreamItemsRecord(streamItemsRecord, [
|
|
1591
|
+
value
|
|
1592
|
+
]),
|
|
1304
1593
|
(error) => {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1594
|
+
incrementalPublisher.filter(path, streamItemsRecord);
|
|
1595
|
+
incrementalPublisher.markErroredStreamItemsRecord(
|
|
1596
|
+
streamItemsRecord,
|
|
1597
|
+
error
|
|
1598
|
+
);
|
|
1308
1599
|
}
|
|
1309
1600
|
);
|
|
1310
|
-
|
|
1311
|
-
return incrementalDataRecord;
|
|
1601
|
+
return streamItemsRecord;
|
|
1312
1602
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1603
|
+
incrementalPublisher.completeStreamItemsRecord(streamItemsRecord, [
|
|
1604
|
+
completedItem
|
|
1605
|
+
]);
|
|
1606
|
+
return streamItemsRecord;
|
|
1315
1607
|
}
|
|
1316
|
-
function executeStreamAsyncIteratorItem(asyncIterator, exeContext, fieldGroup, info,
|
|
1608
|
+
function executeStreamAsyncIteratorItem(asyncIterator, exeContext, fieldGroup, info, itemTypeName, streamItemsRecord, itemPath) {
|
|
1317
1609
|
return __async(this, null, function* () {
|
|
1318
1610
|
let item;
|
|
1319
1611
|
try {
|
|
1320
|
-
const
|
|
1321
|
-
if (
|
|
1322
|
-
|
|
1323
|
-
return { done, value: void 0 };
|
|
1612
|
+
const iteration = yield asyncIterator.next();
|
|
1613
|
+
if (streamItemsRecord.streamRecord.errors.length > 0) {
|
|
1614
|
+
return { done: true, value: void 0 };
|
|
1324
1615
|
}
|
|
1325
|
-
|
|
1616
|
+
if (iteration.done) {
|
|
1617
|
+
exeContext.incrementalPublisher.setIsCompletedAsyncIterator(
|
|
1618
|
+
streamItemsRecord
|
|
1619
|
+
);
|
|
1620
|
+
return { done: true, value: void 0 };
|
|
1621
|
+
}
|
|
1622
|
+
item = iteration.value;
|
|
1326
1623
|
} catch (rawError) {
|
|
1327
|
-
throw locatedError(
|
|
1624
|
+
throw locatedError(
|
|
1625
|
+
rawError,
|
|
1626
|
+
toNodes(fieldGroup),
|
|
1627
|
+
streamItemsRecord.streamRecord.path
|
|
1628
|
+
);
|
|
1328
1629
|
}
|
|
1329
1630
|
let completedItem;
|
|
1330
1631
|
try {
|
|
1331
1632
|
completedItem = completeValue(
|
|
1332
1633
|
exeContext,
|
|
1333
|
-
|
|
1634
|
+
itemTypeName,
|
|
1334
1635
|
fieldGroup,
|
|
1335
1636
|
info,
|
|
1336
1637
|
itemPath,
|
|
1337
1638
|
item,
|
|
1338
|
-
|
|
1639
|
+
streamItemsRecord,
|
|
1640
|
+
/* @__PURE__ */ new Map()
|
|
1339
1641
|
);
|
|
1340
1642
|
if (isPromise(completedItem)) {
|
|
1341
1643
|
completedItem = completedItem.then(void 0, (rawError) => {
|
|
1342
1644
|
handleFieldError(
|
|
1343
1645
|
rawError,
|
|
1344
1646
|
exeContext,
|
|
1345
|
-
|
|
1647
|
+
itemTypeName,
|
|
1346
1648
|
fieldGroup,
|
|
1347
1649
|
itemPath,
|
|
1348
|
-
|
|
1650
|
+
streamItemsRecord
|
|
1349
1651
|
);
|
|
1350
|
-
|
|
1652
|
+
exeContext.incrementalPublisher.filter(itemPath, streamItemsRecord);
|
|
1351
1653
|
return null;
|
|
1352
1654
|
});
|
|
1353
1655
|
}
|
|
@@ -1356,29 +1658,31 @@ function executeStreamAsyncIteratorItem(asyncIterator, exeContext, fieldGroup, i
|
|
|
1356
1658
|
handleFieldError(
|
|
1357
1659
|
rawError,
|
|
1358
1660
|
exeContext,
|
|
1359
|
-
|
|
1661
|
+
itemTypeName,
|
|
1360
1662
|
fieldGroup,
|
|
1361
1663
|
itemPath,
|
|
1362
|
-
|
|
1664
|
+
streamItemsRecord
|
|
1363
1665
|
);
|
|
1364
|
-
|
|
1666
|
+
exeContext.incrementalPublisher.filter(itemPath, streamItemsRecord);
|
|
1365
1667
|
return { done: false, value: null };
|
|
1366
1668
|
}
|
|
1367
1669
|
});
|
|
1368
1670
|
}
|
|
1369
|
-
function executeStreamAsyncIterator(initialIndex, asyncIterator, exeContext, fieldGroup, info,
|
|
1671
|
+
function executeStreamAsyncIterator(initialIndex, asyncIterator, exeContext, fieldGroup, info, itemTypeName, path, incrementalDataRecord, streamRecord) {
|
|
1370
1672
|
return __async(this, null, function* () {
|
|
1673
|
+
const incrementalPublisher = exeContext.incrementalPublisher;
|
|
1371
1674
|
let index = initialIndex;
|
|
1372
|
-
let
|
|
1675
|
+
let currentIncrementalDataRecord = incrementalDataRecord;
|
|
1373
1676
|
while (true) {
|
|
1374
1677
|
const itemPath = addPath(path, index, void 0);
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
path: itemPath
|
|
1378
|
-
parentContext: previousIncrementalDataRecord,
|
|
1379
|
-
asyncIterator,
|
|
1380
|
-
exeContext
|
|
1678
|
+
const streamItemsRecord = new StreamItemsRecord({
|
|
1679
|
+
streamRecord,
|
|
1680
|
+
path: itemPath
|
|
1381
1681
|
});
|
|
1682
|
+
incrementalPublisher.reportNewStreamItemsRecord(
|
|
1683
|
+
streamItemsRecord,
|
|
1684
|
+
currentIncrementalDataRecord
|
|
1685
|
+
);
|
|
1382
1686
|
let iteration;
|
|
1383
1687
|
try {
|
|
1384
1688
|
iteration = yield executeStreamAsyncIteratorItem(
|
|
@@ -1386,223 +1690,47 @@ function executeStreamAsyncIterator(initialIndex, asyncIterator, exeContext, fie
|
|
|
1386
1690
|
exeContext,
|
|
1387
1691
|
fieldGroup,
|
|
1388
1692
|
info,
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
path,
|
|
1693
|
+
itemTypeName,
|
|
1694
|
+
streamItemsRecord,
|
|
1392
1695
|
itemPath
|
|
1393
1696
|
);
|
|
1394
1697
|
} catch (error) {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1698
|
+
incrementalPublisher.filter(path, streamItemsRecord);
|
|
1699
|
+
incrementalPublisher.markErroredStreamItemsRecord(
|
|
1700
|
+
streamItemsRecord,
|
|
1701
|
+
error
|
|
1702
|
+
);
|
|
1402
1703
|
return;
|
|
1403
1704
|
}
|
|
1404
1705
|
const { done, value: completedItem } = iteration;
|
|
1405
|
-
let completedItems;
|
|
1406
1706
|
if (isPromise(completedItem)) {
|
|
1407
|
-
|
|
1408
|
-
(value) => [
|
|
1707
|
+
completedItem.then(
|
|
1708
|
+
(value) => incrementalPublisher.completeStreamItemsRecord(streamItemsRecord, [
|
|
1709
|
+
value
|
|
1710
|
+
]),
|
|
1409
1711
|
(error) => {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1712
|
+
incrementalPublisher.filter(path, streamItemsRecord);
|
|
1713
|
+
incrementalPublisher.markErroredStreamItemsRecord(
|
|
1714
|
+
streamItemsRecord,
|
|
1715
|
+
error
|
|
1716
|
+
);
|
|
1413
1717
|
}
|
|
1414
1718
|
);
|
|
1415
1719
|
} else {
|
|
1416
|
-
|
|
1720
|
+
incrementalPublisher.completeStreamItemsRecord(streamItemsRecord, [
|
|
1721
|
+
completedItem
|
|
1722
|
+
]);
|
|
1417
1723
|
}
|
|
1418
|
-
incrementalDataRecord.addItems(completedItems);
|
|
1419
1724
|
if (done) {
|
|
1420
1725
|
break;
|
|
1421
1726
|
}
|
|
1422
|
-
|
|
1727
|
+
currentIncrementalDataRecord = streamItemsRecord;
|
|
1423
1728
|
index++;
|
|
1424
1729
|
}
|
|
1425
1730
|
});
|
|
1426
1731
|
}
|
|
1427
|
-
function
|
|
1428
|
-
|
|
1429
|
-
exeContext.subsequentPayloads.forEach((incrementalDataRecord) => {
|
|
1430
|
-
var _a;
|
|
1431
|
-
if (incrementalDataRecord === currentIncrementalDataRecord) {
|
|
1432
|
-
return;
|
|
1433
|
-
}
|
|
1434
|
-
for (let i = 0; i < nullPathArray.length; i++) {
|
|
1435
|
-
if (incrementalDataRecord.path[i] !== nullPathArray[i]) {
|
|
1436
|
-
return;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
if (isStreamItemsRecord(incrementalDataRecord) && ((_a = incrementalDataRecord.asyncIterator) == null ? void 0 : _a.return)) {
|
|
1440
|
-
incrementalDataRecord.asyncIterator.return().catch(() => {
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
exeContext.subsequentPayloads.delete(incrementalDataRecord);
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
function getCompletedIncrementalResults(exeContext) {
|
|
1447
|
-
const incrementalResults = [];
|
|
1448
|
-
for (const incrementalDataRecord of exeContext.subsequentPayloads) {
|
|
1449
|
-
const incrementalResult = {};
|
|
1450
|
-
if (!incrementalDataRecord.isCompleted) {
|
|
1451
|
-
continue;
|
|
1452
|
-
}
|
|
1453
|
-
exeContext.subsequentPayloads.delete(incrementalDataRecord);
|
|
1454
|
-
if (isStreamItemsRecord(incrementalDataRecord)) {
|
|
1455
|
-
const items = incrementalDataRecord.items;
|
|
1456
|
-
if (incrementalDataRecord.isCompletedAsyncIterator) {
|
|
1457
|
-
continue;
|
|
1458
|
-
}
|
|
1459
|
-
incrementalResult.items = items;
|
|
1460
|
-
} else {
|
|
1461
|
-
const data = incrementalDataRecord.data;
|
|
1462
|
-
incrementalResult.data = data != null ? data : null;
|
|
1463
|
-
}
|
|
1464
|
-
incrementalResult.path = incrementalDataRecord.path;
|
|
1465
|
-
if (incrementalDataRecord.label != null) {
|
|
1466
|
-
incrementalResult.label = incrementalDataRecord.label;
|
|
1467
|
-
}
|
|
1468
|
-
if (incrementalDataRecord.errors.length > 0) {
|
|
1469
|
-
incrementalResult.errors = incrementalDataRecord.errors;
|
|
1470
|
-
}
|
|
1471
|
-
incrementalResults.push(incrementalResult);
|
|
1472
|
-
}
|
|
1473
|
-
return incrementalResults;
|
|
1474
|
-
}
|
|
1475
|
-
function yieldSubsequentPayloads(exeContext) {
|
|
1476
|
-
let isDone = false;
|
|
1477
|
-
function next() {
|
|
1478
|
-
return __async(this, null, function* () {
|
|
1479
|
-
if (isDone) {
|
|
1480
|
-
return { value: void 0, done: true };
|
|
1481
|
-
}
|
|
1482
|
-
yield Promise.race(
|
|
1483
|
-
Array.from(exeContext.subsequentPayloads).map((p) => p.promise)
|
|
1484
|
-
);
|
|
1485
|
-
if (isDone) {
|
|
1486
|
-
return { value: void 0, done: true };
|
|
1487
|
-
}
|
|
1488
|
-
const incremental = getCompletedIncrementalResults(exeContext);
|
|
1489
|
-
const hasNext = exeContext.subsequentPayloads.size > 0;
|
|
1490
|
-
if (!incremental.length && hasNext) {
|
|
1491
|
-
return next();
|
|
1492
|
-
}
|
|
1493
|
-
if (!hasNext) {
|
|
1494
|
-
isDone = true;
|
|
1495
|
-
}
|
|
1496
|
-
return {
|
|
1497
|
-
value: incremental.length ? { incremental, hasNext } : { hasNext },
|
|
1498
|
-
done: false
|
|
1499
|
-
};
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
function returnStreamIterators() {
|
|
1503
|
-
const promises = [];
|
|
1504
|
-
exeContext.subsequentPayloads.forEach((incrementalDataRecord) => {
|
|
1505
|
-
var _a2;
|
|
1506
|
-
if (isStreamItemsRecord(incrementalDataRecord) && ((_a2 = incrementalDataRecord.asyncIterator) == null ? void 0 : _a2.return)) {
|
|
1507
|
-
promises.push(incrementalDataRecord.asyncIterator.return());
|
|
1508
|
-
}
|
|
1509
|
-
});
|
|
1510
|
-
return Promise.all(promises);
|
|
1511
|
-
}
|
|
1512
|
-
return {
|
|
1513
|
-
[Symbol.asyncIterator]() {
|
|
1514
|
-
return this;
|
|
1515
|
-
},
|
|
1516
|
-
next,
|
|
1517
|
-
return() {
|
|
1518
|
-
return __async(this, null, function* () {
|
|
1519
|
-
yield returnStreamIterators();
|
|
1520
|
-
isDone = true;
|
|
1521
|
-
return { value: void 0, done: true };
|
|
1522
|
-
});
|
|
1523
|
-
},
|
|
1524
|
-
throw(error) {
|
|
1525
|
-
return __async(this, null, function* () {
|
|
1526
|
-
yield returnStreamIterators();
|
|
1527
|
-
isDone = true;
|
|
1528
|
-
return Promise.reject(error);
|
|
1529
|
-
});
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
}
|
|
1533
|
-
function isStreamItemsRecord(incrementalDataRecord) {
|
|
1534
|
-
return incrementalDataRecord.type === "stream";
|
|
1535
|
-
}
|
|
1536
|
-
var DeferredFragmentRecord = class {
|
|
1537
|
-
constructor(opts) {
|
|
1538
|
-
this.type = "defer";
|
|
1539
|
-
this.label = opts.label;
|
|
1540
|
-
this.path = pathToArray(opts.path);
|
|
1541
|
-
this.parentContext = opts.parentContext;
|
|
1542
|
-
this.errors = [];
|
|
1543
|
-
this._exeContext = opts.exeContext;
|
|
1544
|
-
this._exeContext.subsequentPayloads.add(this);
|
|
1545
|
-
this.isCompleted = false;
|
|
1546
|
-
this.data = null;
|
|
1547
|
-
this.promise = new Promise((resolve) => {
|
|
1548
|
-
this._resolve = (promiseOrValue) => {
|
|
1549
|
-
resolve(promiseOrValue);
|
|
1550
|
-
};
|
|
1551
|
-
}).then((data) => {
|
|
1552
|
-
this.data = data;
|
|
1553
|
-
this.isCompleted = true;
|
|
1554
|
-
});
|
|
1555
|
-
}
|
|
1556
|
-
addData(data) {
|
|
1557
|
-
var _a, _b, _c;
|
|
1558
|
-
const parentData = (_a = this.parentContext) == null ? void 0 : _a.promise;
|
|
1559
|
-
if (parentData) {
|
|
1560
|
-
(_b = this._resolve) == null ? void 0 : _b.call(this, parentData.then(() => data));
|
|
1561
|
-
return;
|
|
1562
|
-
}
|
|
1563
|
-
(_c = this._resolve) == null ? void 0 : _c.call(this, data);
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
var StreamItemsRecord = class {
|
|
1567
|
-
constructor(opts) {
|
|
1568
|
-
this.type = "stream";
|
|
1569
|
-
this.items = null;
|
|
1570
|
-
this.label = opts.label;
|
|
1571
|
-
this.path = pathToArray(opts.path);
|
|
1572
|
-
this.parentContext = opts.parentContext;
|
|
1573
|
-
this.asyncIterator = opts.asyncIterator;
|
|
1574
|
-
this.errors = [];
|
|
1575
|
-
this._exeContext = opts.exeContext;
|
|
1576
|
-
this._exeContext.subsequentPayloads.add(this);
|
|
1577
|
-
this.isCompleted = false;
|
|
1578
|
-
this.items = null;
|
|
1579
|
-
this.promise = new Promise((resolve) => {
|
|
1580
|
-
this._resolve = (promiseOrValue) => {
|
|
1581
|
-
resolve(promiseOrValue);
|
|
1582
|
-
};
|
|
1583
|
-
}).then((items) => {
|
|
1584
|
-
this.items = items;
|
|
1585
|
-
this.isCompleted = true;
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
addItems(items) {
|
|
1589
|
-
var _a, _b, _c;
|
|
1590
|
-
const parentData = (_a = this.parentContext) == null ? void 0 : _a.promise;
|
|
1591
|
-
if (parentData) {
|
|
1592
|
-
(_b = this._resolve) == null ? void 0 : _b.call(this, parentData.then(() => items));
|
|
1593
|
-
return;
|
|
1594
|
-
}
|
|
1595
|
-
(_c = this._resolve) == null ? void 0 : _c.call(this, items);
|
|
1596
|
-
}
|
|
1597
|
-
setIsCompletedAsyncIterator() {
|
|
1598
|
-
this.isCompletedAsyncIterator = true;
|
|
1599
|
-
}
|
|
1600
|
-
};
|
|
1601
|
-
function isIncrementalExecutionResult(result) {
|
|
1602
|
-
return "initialResult" in result;
|
|
1603
|
-
}
|
|
1604
|
-
function isTotalExecutionResult(result) {
|
|
1605
|
-
return !("initialResult" in result);
|
|
1732
|
+
function toNodes(fieldGroup) {
|
|
1733
|
+
return fieldGroup.fields.map((fieldDetails) => fieldDetails.node);
|
|
1606
1734
|
}
|
|
1607
1735
|
export {
|
|
1608
1736
|
assertValidExecutionArguments,
|