@graphql-tools/executor 2.0.0-alpha-20240709212042-9a70c086fa543c594055305622a600bb95343b42 → 2.0.0-alpha-20240804112853-812acba5ea59541106a53f872874fd7aebcffcfc
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/cjs/execution/IncrementalGraph.js +42 -43
- package/cjs/execution/IncrementalPublisher.js +17 -17
- package/cjs/execution/{buildFieldPlan.js → buildExecutionPlan.js} +29 -42
- package/cjs/execution/execute.js +148 -114
- package/cjs/execution/types.js +17 -17
- package/esm/execution/IncrementalGraph.js +43 -44
- package/esm/execution/IncrementalPublisher.js +18 -18
- package/esm/execution/{buildFieldPlan.js → buildExecutionPlan.js} +26 -39
- package/esm/execution/execute.js +147 -113
- package/esm/execution/types.js +13 -13
- package/package.json +2 -2
- package/typings/execution/IncrementalGraph.d.cts +6 -7
- package/typings/execution/IncrementalGraph.d.ts +6 -7
- package/typings/execution/buildExecutionPlan.d.cts +8 -0
- package/typings/execution/buildExecutionPlan.d.ts +8 -0
- package/typings/execution/execute.d.cts +3 -1
- package/typings/execution/execute.d.ts +3 -1
- package/typings/execution/types.d.cts +22 -22
- package/typings/execution/types.d.ts +22 -22
- package/typings/execution/buildFieldPlan.d.cts +0 -8
- package/typings/execution/buildFieldPlan.d.ts +0 -8
package/cjs/execution/execute.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isIncrementalResult = exports.getFieldDef = exports.flattenIncrementalResults = exports.subscribe = exports.defaultFieldResolver = exports.defaultTypeResolver = exports.buildResolveInfo = exports.buildExecutionContext = exports.getFragmentsFromDocument = exports.assertValidExecutionArguments = exports.executeSync = exports.execute = void 0;
|
|
3
|
+
exports.isIncrementalResult = exports.getFieldDef = exports.flattenIncrementalResults = exports.subscribe = exports.defaultFieldResolver = exports.defaultTypeResolver = exports.CRITICAL_ERROR = exports.buildResolveInfo = exports.buildExecutionContext = exports.getFragmentsFromDocument = exports.assertValidExecutionArguments = exports.executeSync = exports.execute = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
+
const AccumulatorMap_js_1 = require("./AccumulatorMap.js");
|
|
6
7
|
const BoxedPromiseOrValue_js_1 = require("./BoxedPromiseOrValue.js");
|
|
7
|
-
const
|
|
8
|
+
const buildExecutionPlan_js_1 = require("./buildExecutionPlan.js");
|
|
8
9
|
const coerceError_js_1 = require("./coerceError.js");
|
|
9
10
|
const collectFields_js_1 = require("./collectFields.js");
|
|
10
11
|
const flattenAsyncIterable_js_1 = require("./flattenAsyncIterable.js");
|
|
@@ -85,10 +86,10 @@ function buildDataResponse(exeContext, data) {
|
|
|
85
86
|
if (filteredIncrementalDataRecords.length === 0) {
|
|
86
87
|
return buildSingleResult(data, errors);
|
|
87
88
|
}
|
|
88
|
-
return (0, IncrementalPublisher_js_1.buildIncrementalResponse)(exeContext, data,
|
|
89
|
+
return (0, IncrementalPublisher_js_1.buildIncrementalResponse)(exeContext, data, flattenErrors(errors), filteredIncrementalDataRecords);
|
|
89
90
|
}
|
|
90
91
|
function buildSingleResult(data, errors) {
|
|
91
|
-
return errors !== undefined ? { errors: Array.from(errors.values()), data } : { data };
|
|
92
|
+
return errors !== undefined ? { errors: Array.from(errors.values()).flat(), data } : { data };
|
|
92
93
|
}
|
|
93
94
|
function filterIncrementalDataRecords(initialPath, errors, incrementalDataRecords) {
|
|
94
95
|
const filteredIncrementalDataRecords = [];
|
|
@@ -117,6 +118,10 @@ function filterIncrementalDataRecords(initialPath, errors, incrementalDataRecord
|
|
|
117
118
|
}
|
|
118
119
|
return filteredIncrementalDataRecords;
|
|
119
120
|
}
|
|
121
|
+
function flattenErrors(errors) {
|
|
122
|
+
const errorsByPath = [...errors.values()];
|
|
123
|
+
return errorsByPath.flat();
|
|
124
|
+
}
|
|
120
125
|
/**
|
|
121
126
|
* Essential assertions before executing to provide developer feedback for
|
|
122
127
|
* improper use of the GraphQL library.
|
|
@@ -241,16 +246,16 @@ function executeOperation(exeContext) {
|
|
|
241
246
|
data = executeRootGroupedFieldSet(exeContext, operation.operation, rootType, rootValue, groupedFieldSet, undefined);
|
|
242
247
|
}
|
|
243
248
|
else {
|
|
244
|
-
const
|
|
245
|
-
? (0,
|
|
246
|
-
: (0,
|
|
247
|
-
groupedFieldSet =
|
|
248
|
-
const newGroupedFieldSets =
|
|
249
|
+
const executionPlan = deduplicateDefers
|
|
250
|
+
? (0, buildExecutionPlan_js_1.buildExecutionPlan)(groupedFieldSet)
|
|
251
|
+
: (0, buildExecutionPlan_js_1.buildBranchingExecutionPlan)(groupedFieldSet);
|
|
252
|
+
groupedFieldSet = executionPlan.groupedFieldSet;
|
|
253
|
+
const newGroupedFieldSets = executionPlan.newGroupedFieldSets;
|
|
249
254
|
const newDeferMap = addNewDeferredFragments(newDeferUsages, new Map());
|
|
250
255
|
data = executeRootGroupedFieldSet(exeContext, operation.operation, rootType, rootValue, groupedFieldSet, newDeferMap);
|
|
251
256
|
if (newGroupedFieldSets.size > 0) {
|
|
252
|
-
const
|
|
253
|
-
addIncrementalDataRecords(exeContext,
|
|
257
|
+
const newPendingExecutionGroups = collectExecutionGroups(exeContext, rootType, rootValue, undefined, undefined, newGroupedFieldSets, newDeferMap);
|
|
258
|
+
addIncrementalDataRecords(exeContext, newPendingExecutionGroups);
|
|
254
259
|
}
|
|
255
260
|
}
|
|
256
261
|
if ((0, utils_1.isPromise)(data)) {
|
|
@@ -292,7 +297,8 @@ function addIncrementalDataRecords(context, newIncrementalDataRecords) {
|
|
|
292
297
|
incrementalDataRecords.push(...newIncrementalDataRecords);
|
|
293
298
|
}
|
|
294
299
|
function withError(errors, error) {
|
|
295
|
-
|
|
300
|
+
const newErrors = 'errors' in error ? error.errors : [error];
|
|
301
|
+
return errors === undefined ? newErrors : [...flattenErrors(errors), ...newErrors];
|
|
296
302
|
}
|
|
297
303
|
/**
|
|
298
304
|
* Implements the "Executing selection sets" section of the spec
|
|
@@ -426,22 +432,32 @@ function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
|
|
|
426
432
|
};
|
|
427
433
|
}
|
|
428
434
|
exports.buildResolveInfo = buildResolveInfo;
|
|
435
|
+
exports.CRITICAL_ERROR = 'CRITICAL_ERROR';
|
|
429
436
|
function handleFieldError(rawError, exeContext, returnType, fieldGroup, path, incrementalContext) {
|
|
437
|
+
if (rawError instanceof AggregateError) {
|
|
438
|
+
for (const rawErrorItem of rawError.errors) {
|
|
439
|
+
handleFieldError(rawErrorItem, exeContext, returnType, fieldGroup, path, incrementalContext);
|
|
440
|
+
}
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
430
443
|
const error = (0, graphql_1.locatedError)((0, coerceError_js_1.coerceError)(rawError), toNodes(fieldGroup), (0, utils_1.pathToArray)(path));
|
|
431
444
|
// If the field type is non-nullable, then it is resolved without any
|
|
432
445
|
// protection from errors, however it still properly locates the error.
|
|
433
446
|
if ((0, graphql_1.isNonNullType)(returnType)) {
|
|
434
447
|
throw error;
|
|
435
448
|
}
|
|
449
|
+
if (error.extensions?.[exports.CRITICAL_ERROR]) {
|
|
450
|
+
throw error;
|
|
451
|
+
}
|
|
436
452
|
// Otherwise, error protection is applied, logging the error and resolving
|
|
437
453
|
// a null value for this field if one is encountered.
|
|
438
454
|
const context = incrementalContext ?? exeContext;
|
|
439
455
|
let errors = context.errors;
|
|
440
456
|
if (errors === undefined) {
|
|
441
|
-
errors = new
|
|
457
|
+
errors = new AccumulatorMap_js_1.AccumulatorMap();
|
|
442
458
|
context.errors = errors;
|
|
443
459
|
}
|
|
444
|
-
errors.
|
|
460
|
+
errors.add(path, error);
|
|
445
461
|
}
|
|
446
462
|
/**
|
|
447
463
|
* Implements the instructions for completeValue as defined in the
|
|
@@ -569,66 +585,77 @@ async function completeAsyncIteratorValue(exeContext, itemType, fieldGroup, info
|
|
|
569
585
|
const completedResults = [];
|
|
570
586
|
let index = 0;
|
|
571
587
|
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
else {
|
|
586
|
-
streamRecord = {
|
|
587
|
-
label: streamUsage.label,
|
|
588
|
-
path,
|
|
589
|
-
index,
|
|
590
|
-
streamItemQueue,
|
|
591
|
-
earlyReturn: returnFn.bind(asyncIterator),
|
|
592
|
-
};
|
|
593
|
-
if (exeContext.cancellableStreams === undefined) {
|
|
594
|
-
exeContext.cancellableStreams = new Set();
|
|
588
|
+
const earlyReturn = asyncIterator.return === undefined ? undefined : asyncIterator.return.bind(asyncIterator);
|
|
589
|
+
try {
|
|
590
|
+
while (true) {
|
|
591
|
+
if (streamUsage && index >= streamUsage.initialCount) {
|
|
592
|
+
const streamItemQueue = buildAsyncStreamItemQueue(index, path, asyncIterator, exeContext, streamUsage.fieldGroup, info, itemType);
|
|
593
|
+
let streamRecord;
|
|
594
|
+
if (earlyReturn === undefined) {
|
|
595
|
+
streamRecord = {
|
|
596
|
+
label: streamUsage.label,
|
|
597
|
+
path,
|
|
598
|
+
index,
|
|
599
|
+
streamItemQueue,
|
|
600
|
+
};
|
|
595
601
|
}
|
|
596
|
-
|
|
602
|
+
else {
|
|
603
|
+
streamRecord = {
|
|
604
|
+
label: streamUsage.label,
|
|
605
|
+
path,
|
|
606
|
+
index,
|
|
607
|
+
streamItemQueue,
|
|
608
|
+
earlyReturn,
|
|
609
|
+
};
|
|
610
|
+
if (exeContext.cancellableStreams === undefined) {
|
|
611
|
+
exeContext.cancellableStreams = new Set();
|
|
612
|
+
}
|
|
613
|
+
exeContext.cancellableStreams.add(streamRecord);
|
|
614
|
+
}
|
|
615
|
+
const context = incrementalContext ?? exeContext;
|
|
616
|
+
addIncrementalDataRecords(context, [streamRecord]);
|
|
617
|
+
break;
|
|
597
618
|
}
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
619
|
+
const itemPath = (0, utils_1.addPath)(path, index, undefined);
|
|
620
|
+
let iteration;
|
|
621
|
+
try {
|
|
622
|
+
iteration = await asyncIterator.next();
|
|
623
|
+
}
|
|
624
|
+
catch (rawError) {
|
|
625
|
+
throw (0, graphql_1.locatedError)((0, coerceError_js_1.coerceError)(rawError), toNodes(fieldGroup), (0, utils_1.pathToArray)(path));
|
|
626
|
+
}
|
|
627
|
+
// TODO: add test case for stream returning done before initialCount
|
|
628
|
+
/* c8 ignore next 3 */
|
|
629
|
+
if (iteration.done) {
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
const item = iteration.value;
|
|
633
|
+
// TODO: add tests for stream backed by asyncIterator that returns a promise
|
|
634
|
+
/* c8 ignore start */
|
|
635
|
+
if ((0, utils_1.isPromise)(item)) {
|
|
636
|
+
completedResults.push(completePromisedListItemValue(item, exeContext, itemType, fieldGroup, info, itemPath, incrementalContext, deferMap));
|
|
637
|
+
containsPromise = true;
|
|
638
|
+
}
|
|
639
|
+
else if (
|
|
640
|
+
/* c8 ignore stop */
|
|
641
|
+
completeListItemValue(item, completedResults, exeContext, itemType, fieldGroup, info, itemPath, incrementalContext, deferMap)
|
|
642
|
+
// TODO: add tests for stream backed by asyncIterator that completes to a promise
|
|
643
|
+
/* c8 ignore start */
|
|
644
|
+
) {
|
|
645
|
+
containsPromise = true;
|
|
646
|
+
}
|
|
647
|
+
/* c8 ignore stop */
|
|
648
|
+
index++;
|
|
621
649
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
if (earlyReturn !== undefined) {
|
|
653
|
+
earlyReturn().catch(() => {
|
|
654
|
+
/* c8 ignore next 1 */
|
|
655
|
+
// ignore error
|
|
656
|
+
});
|
|
629
657
|
}
|
|
630
|
-
|
|
631
|
-
index++;
|
|
658
|
+
throw error;
|
|
632
659
|
}
|
|
633
660
|
return containsPromise
|
|
634
661
|
? /* c8 ignore start */ Promise.all(completedResults)
|
|
@@ -842,28 +869,30 @@ function collectAndExecuteSubfields(exeContext, returnType, fieldGroup, path, re
|
|
|
842
869
|
if (deferMap === undefined && newDeferUsages.length === 0) {
|
|
843
870
|
return executeFields(exeContext, returnType, result, path, groupedFieldSet, incrementalContext, undefined);
|
|
844
871
|
}
|
|
845
|
-
const
|
|
846
|
-
groupedFieldSet =
|
|
847
|
-
const newGroupedFieldSets =
|
|
872
|
+
const subExecutionPlan = buildSubExecutionPlan(groupedFieldSet, incrementalContext?.deferUsageSet, exeContext.deduplicateDefers);
|
|
873
|
+
groupedFieldSet = subExecutionPlan.groupedFieldSet;
|
|
874
|
+
const newGroupedFieldSets = subExecutionPlan.newGroupedFieldSets;
|
|
848
875
|
const newDeferMap = addNewDeferredFragments(newDeferUsages, new Map(deferMap), path);
|
|
849
876
|
const subFields = executeFields(exeContext, returnType, result, path, groupedFieldSet, incrementalContext, newDeferMap);
|
|
850
877
|
if (newGroupedFieldSets.size > 0) {
|
|
851
|
-
const
|
|
878
|
+
const newPendingExecutionGroups = collectExecutionGroups(exeContext, returnType, result, path, incrementalContext?.deferUsageSet, newGroupedFieldSets, newDeferMap);
|
|
852
879
|
const context = incrementalContext ?? exeContext;
|
|
853
|
-
addIncrementalDataRecords(context,
|
|
880
|
+
addIncrementalDataRecords(context, newPendingExecutionGroups);
|
|
854
881
|
}
|
|
855
882
|
return subFields;
|
|
856
883
|
}
|
|
857
|
-
function
|
|
858
|
-
let
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
884
|
+
function buildSubExecutionPlan(originalGroupedFieldSet, deferUsageSet, deduplicateDefers) {
|
|
885
|
+
let executionPlan = originalGroupedFieldSet
|
|
886
|
+
._executionPlan;
|
|
887
|
+
if (executionPlan !== undefined) {
|
|
888
|
+
return executionPlan;
|
|
889
|
+
}
|
|
890
|
+
executionPlan = deduplicateDefers
|
|
891
|
+
? (0, buildExecutionPlan_js_1.buildExecutionPlan)(originalGroupedFieldSet, deferUsageSet)
|
|
892
|
+
: (0, buildExecutionPlan_js_1.buildBranchingExecutionPlan)(originalGroupedFieldSet, deferUsageSet);
|
|
893
|
+
originalGroupedFieldSet._executionPlan =
|
|
894
|
+
executionPlan;
|
|
895
|
+
return executionPlan;
|
|
867
896
|
}
|
|
868
897
|
/**
|
|
869
898
|
* If a resolveType function is not given, then a default resolve behavior is
|
|
@@ -1005,13 +1034,18 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
1005
1034
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
1006
1035
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
1007
1036
|
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeOperation(buildPerEventExecutionContext(exeContext, payload))), (error) => {
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
throw wrappedError;
|
|
1037
|
+
if (error instanceof AggregateError) {
|
|
1038
|
+
throw new AggregateError(error.errors.map(e => wrapError(e, exeContext.operation)), error.message);
|
|
1039
|
+
}
|
|
1040
|
+
throw wrapError(error, exeContext.operation);
|
|
1013
1041
|
}));
|
|
1014
1042
|
}
|
|
1043
|
+
function wrapError(error, operation) {
|
|
1044
|
+
return (0, utils_1.createGraphQLError)(error.message, {
|
|
1045
|
+
originalError: error,
|
|
1046
|
+
nodes: [operation],
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1015
1049
|
function createSourceEventStreamImpl(exeContext) {
|
|
1016
1050
|
try {
|
|
1017
1051
|
const eventStream = executeSubscription(exeContext);
|
|
@@ -1087,40 +1121,40 @@ function assertEventStream(result, signal) {
|
|
|
1087
1121
|
},
|
|
1088
1122
|
};
|
|
1089
1123
|
}
|
|
1090
|
-
function
|
|
1091
|
-
const
|
|
1124
|
+
function collectExecutionGroups(exeContext, parentType, sourceValue, path, parentDeferUsages, newGroupedFieldSets, deferMap) {
|
|
1125
|
+
const newPendingExecutionGroups = [];
|
|
1092
1126
|
for (const [deferUsageSet, groupedFieldSet] of newGroupedFieldSets) {
|
|
1093
1127
|
const deferredFragmentRecords = getDeferredFragmentRecords(deferUsageSet, deferMap);
|
|
1094
|
-
const
|
|
1128
|
+
const pendingExecutionGroup = {
|
|
1095
1129
|
path,
|
|
1096
1130
|
deferredFragmentRecords,
|
|
1097
1131
|
result: undefined,
|
|
1098
1132
|
};
|
|
1099
|
-
const executor = () =>
|
|
1133
|
+
const executor = () => executeExecutionGroup(pendingExecutionGroup, exeContext, parentType, sourceValue, path, groupedFieldSet, {
|
|
1100
1134
|
errors: undefined,
|
|
1101
1135
|
deferUsageSet,
|
|
1102
1136
|
incrementalDataRecords: undefined,
|
|
1103
1137
|
}, deferMap);
|
|
1104
1138
|
if (exeContext.enableEarlyExecution) {
|
|
1105
|
-
|
|
1139
|
+
pendingExecutionGroup.result = new BoxedPromiseOrValue_js_1.BoxedPromiseOrValue(shouldDefer(parentDeferUsages, deferUsageSet)
|
|
1106
1140
|
? Promise.resolve().then(executor)
|
|
1107
1141
|
: executor());
|
|
1108
1142
|
}
|
|
1109
1143
|
else {
|
|
1110
|
-
|
|
1144
|
+
pendingExecutionGroup.result = () => new BoxedPromiseOrValue_js_1.BoxedPromiseOrValue(executor());
|
|
1111
1145
|
const resolveThunk = () => {
|
|
1112
|
-
const maybeThunk =
|
|
1146
|
+
const maybeThunk = pendingExecutionGroup.result;
|
|
1113
1147
|
if (!(maybeThunk instanceof BoxedPromiseOrValue_js_1.BoxedPromiseOrValue)) {
|
|
1114
|
-
|
|
1148
|
+
pendingExecutionGroup.result = maybeThunk();
|
|
1115
1149
|
}
|
|
1116
1150
|
};
|
|
1117
1151
|
for (const deferredFragmentRecord of deferredFragmentRecords) {
|
|
1118
1152
|
deferredFragmentRecord.onPending(resolveThunk);
|
|
1119
1153
|
}
|
|
1120
1154
|
}
|
|
1121
|
-
|
|
1155
|
+
newPendingExecutionGroups.push(pendingExecutionGroup);
|
|
1122
1156
|
}
|
|
1123
|
-
return
|
|
1157
|
+
return newPendingExecutionGroups;
|
|
1124
1158
|
}
|
|
1125
1159
|
function shouldDefer(parentDeferUsages, deferUsages) {
|
|
1126
1160
|
// If we have a new child defer usage, defer.
|
|
@@ -1130,49 +1164,49 @@ function shouldDefer(parentDeferUsages, deferUsages) {
|
|
|
1130
1164
|
return (parentDeferUsages === undefined ||
|
|
1131
1165
|
!Array.from(deferUsages).every(deferUsage => parentDeferUsages.has(deferUsage)));
|
|
1132
1166
|
}
|
|
1133
|
-
function
|
|
1167
|
+
function executeExecutionGroup(pendingExecutionGroup, exeContext, parentType, sourceValue, path, groupedFieldSet, incrementalContext, deferMap) {
|
|
1134
1168
|
let result;
|
|
1135
1169
|
try {
|
|
1136
1170
|
result = executeFields(exeContext, parentType, sourceValue, path, groupedFieldSet, incrementalContext, deferMap);
|
|
1137
1171
|
}
|
|
1138
1172
|
catch (error) {
|
|
1139
1173
|
return {
|
|
1140
|
-
|
|
1174
|
+
pendingExecutionGroup,
|
|
1141
1175
|
path: (0, utils_1.pathToArray)(path),
|
|
1142
1176
|
errors: withError(incrementalContext.errors, error),
|
|
1143
1177
|
};
|
|
1144
1178
|
}
|
|
1145
1179
|
if ((0, utils_1.isPromise)(result)) {
|
|
1146
|
-
return result.then(resolved =>
|
|
1147
|
-
|
|
1180
|
+
return result.then(resolved => buildCompletedExecutionGroup(incrementalContext, pendingExecutionGroup, path, resolved), error => ({
|
|
1181
|
+
pendingExecutionGroup,
|
|
1148
1182
|
path: (0, utils_1.pathToArray)(path),
|
|
1149
1183
|
errors: withError(incrementalContext.errors, error),
|
|
1150
1184
|
}));
|
|
1151
1185
|
}
|
|
1152
|
-
return
|
|
1186
|
+
return buildCompletedExecutionGroup(incrementalContext, pendingExecutionGroup, path, result);
|
|
1153
1187
|
}
|
|
1154
|
-
function
|
|
1188
|
+
function buildCompletedExecutionGroup(incrementalContext, pendingExecutionGroup, path, data) {
|
|
1155
1189
|
const { errors, incrementalDataRecords } = incrementalContext;
|
|
1156
1190
|
if (incrementalDataRecords === undefined) {
|
|
1157
1191
|
return {
|
|
1158
|
-
|
|
1192
|
+
pendingExecutionGroup,
|
|
1159
1193
|
path: (0, utils_1.pathToArray)(path),
|
|
1160
|
-
result: errors === undefined ? { data } : { data, errors: [...errors
|
|
1194
|
+
result: errors === undefined ? { data } : { data, errors: [...flattenErrors(errors)] },
|
|
1161
1195
|
incrementalDataRecords,
|
|
1162
1196
|
};
|
|
1163
1197
|
}
|
|
1164
1198
|
if (errors === undefined) {
|
|
1165
1199
|
return {
|
|
1166
|
-
|
|
1200
|
+
pendingExecutionGroup,
|
|
1167
1201
|
path: (0, utils_1.pathToArray)(path),
|
|
1168
1202
|
result: { data },
|
|
1169
1203
|
incrementalDataRecords,
|
|
1170
1204
|
};
|
|
1171
1205
|
}
|
|
1172
1206
|
return {
|
|
1173
|
-
|
|
1207
|
+
pendingExecutionGroup,
|
|
1174
1208
|
path: (0, utils_1.pathToArray)(path),
|
|
1175
|
-
result: { data, errors: [...errors
|
|
1209
|
+
result: { data, errors: [...flattenErrors(errors)] },
|
|
1176
1210
|
incrementalDataRecords: filterIncrementalDataRecords(path, errors, incrementalDataRecords),
|
|
1177
1211
|
};
|
|
1178
1212
|
}
|
|
@@ -1231,7 +1265,7 @@ async function getNextAsyncStreamItemResult(streamItemQueue, streamPath, index,
|
|
|
1231
1265
|
catch (error) {
|
|
1232
1266
|
return {
|
|
1233
1267
|
path: streamPath,
|
|
1234
|
-
errors: [(0, graphql_1.locatedError)(error, toNodes(fieldGroup), (0, utils_1.pathToArray)(streamPath))],
|
|
1268
|
+
errors: [(0, graphql_1.locatedError)((0, coerceError_js_1.coerceError)(error), toNodes(fieldGroup), (0, utils_1.pathToArray)(streamPath))],
|
|
1235
1269
|
};
|
|
1236
1270
|
}
|
|
1237
1271
|
if (iteration.done) {
|
|
@@ -1287,7 +1321,7 @@ function buildStreamItemResult(incrementalContext, streamPath, item) {
|
|
|
1287
1321
|
return {
|
|
1288
1322
|
path: streamPath,
|
|
1289
1323
|
item,
|
|
1290
|
-
errors: errors === undefined ? undefined : [...errors
|
|
1324
|
+
errors: errors === undefined ? undefined : [...flattenErrors(errors)],
|
|
1291
1325
|
incrementalDataRecords,
|
|
1292
1326
|
};
|
|
1293
1327
|
}
|
|
@@ -1302,7 +1336,7 @@ function buildStreamItemResult(incrementalContext, streamPath, item) {
|
|
|
1302
1336
|
return {
|
|
1303
1337
|
path: streamPath,
|
|
1304
1338
|
item,
|
|
1305
|
-
errors: [...errors
|
|
1339
|
+
errors: [...flattenErrors(errors)],
|
|
1306
1340
|
incrementalDataRecords: filterIncrementalDataRecords(streamPath, errors, incrementalDataRecords),
|
|
1307
1341
|
};
|
|
1308
1342
|
}
|
package/cjs/execution/types.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCancellableStreamRecord = exports.isDeferredFragmentRecord = exports.DeferredFragmentRecord = exports.
|
|
4
|
-
function
|
|
3
|
+
exports.isCancellableStreamRecord = exports.isDeferredFragmentRecord = exports.DeferredFragmentRecord = exports.isFailedExecutionGroup = exports.isCompletedExecutionGroup = exports.isPendingExecutionGroup = void 0;
|
|
4
|
+
function isPendingExecutionGroup(incrementalDataRecord) {
|
|
5
5
|
return 'deferredFragmentRecords' in incrementalDataRecord;
|
|
6
6
|
}
|
|
7
|
-
exports.
|
|
8
|
-
function
|
|
9
|
-
return '
|
|
7
|
+
exports.isPendingExecutionGroup = isPendingExecutionGroup;
|
|
8
|
+
function isCompletedExecutionGroup(incrementalDataRecordResult) {
|
|
9
|
+
return 'pendingExecutionGroup' in incrementalDataRecordResult;
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
12
|
-
function
|
|
13
|
-
return
|
|
11
|
+
exports.isCompletedExecutionGroup = isCompletedExecutionGroup;
|
|
12
|
+
function isFailedExecutionGroup(completedExecutionGroup) {
|
|
13
|
+
return completedExecutionGroup.errors !== undefined;
|
|
14
14
|
}
|
|
15
|
-
exports.
|
|
15
|
+
exports.isFailedExecutionGroup = isFailedExecutionGroup;
|
|
16
16
|
/** @internal */
|
|
17
17
|
class DeferredFragmentRecord {
|
|
18
18
|
path;
|
|
19
19
|
label;
|
|
20
20
|
id;
|
|
21
21
|
parent;
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
pendingExecutionGroups;
|
|
23
|
+
successfulExecutionGroups;
|
|
24
24
|
children;
|
|
25
25
|
pending;
|
|
26
26
|
fns;
|
|
@@ -28,8 +28,8 @@ class DeferredFragmentRecord {
|
|
|
28
28
|
this.path = path;
|
|
29
29
|
this.label = label;
|
|
30
30
|
this.parent = parent;
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
31
|
+
this.pendingExecutionGroups = new Set();
|
|
32
|
+
this.successfulExecutionGroups = new Set();
|
|
33
33
|
this.children = new Set();
|
|
34
34
|
this.pending = false;
|
|
35
35
|
this.fns = [];
|
|
@@ -45,11 +45,11 @@ class DeferredFragmentRecord {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.DeferredFragmentRecord = DeferredFragmentRecord;
|
|
48
|
-
function isDeferredFragmentRecord(
|
|
49
|
-
return
|
|
48
|
+
function isDeferredFragmentRecord(deliveryGroup) {
|
|
49
|
+
return deliveryGroup instanceof DeferredFragmentRecord;
|
|
50
50
|
}
|
|
51
51
|
exports.isDeferredFragmentRecord = isDeferredFragmentRecord;
|
|
52
|
-
function isCancellableStreamRecord(
|
|
53
|
-
return 'earlyReturn' in
|
|
52
|
+
function isCancellableStreamRecord(deliveryGroup) {
|
|
53
|
+
return 'earlyReturn' in deliveryGroup;
|
|
54
54
|
}
|
|
55
55
|
exports.isCancellableStreamRecord = isCancellableStreamRecord;
|