@graphql-tools/executor 1.2.4 → 1.2.5-alpha-20240328143324-239661c7f22ace5ca5539cc5b2e9f2e5fb67b38c
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/execute.js +21 -69
- package/cjs/execution/normalizedExecutor.js +1 -1
- package/cjs/execution/promiseForObject.js +1 -1
- package/esm/execution/execute.js +21 -69
- package/esm/execution/normalizedExecutor.js +1 -1
- package/esm/execution/promiseForObject.js +1 -1
- package/package.json +1 -1
- package/typings/execution/execute.d.cts +1 -5
- package/typings/execution/execute.d.ts +1 -5
package/cjs/execution/execute.js
CHANGED
|
@@ -79,28 +79,14 @@ function executeImpl(exeContext) {
|
|
|
79
79
|
}
|
|
80
80
|
return initialResult;
|
|
81
81
|
}, (error) => {
|
|
82
|
+
if (exeContext.signal?.aborted) {
|
|
83
|
+
throw exeContext.signal.reason;
|
|
84
|
+
}
|
|
82
85
|
exeContext.errors.push(error);
|
|
83
86
|
return buildResponse(null, exeContext.errors);
|
|
84
87
|
})
|
|
85
88
|
.resolve();
|
|
86
|
-
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
let resolve;
|
|
90
|
-
let reject;
|
|
91
|
-
const abortP = new Promise((_resolve, _reject) => {
|
|
92
|
-
resolve = _resolve;
|
|
93
|
-
reject = _reject;
|
|
94
|
-
});
|
|
95
|
-
function abortListener() {
|
|
96
|
-
reject(exeContext.signal?.reason);
|
|
97
|
-
}
|
|
98
|
-
exeContext.signal.addEventListener('abort', abortListener);
|
|
99
|
-
result.then(() => {
|
|
100
|
-
exeContext.signal?.removeEventListener('abort', abortListener);
|
|
101
|
-
resolve();
|
|
102
|
-
});
|
|
103
|
-
return Promise.race([abortP, result]);
|
|
89
|
+
return result;
|
|
104
90
|
}
|
|
105
91
|
/**
|
|
106
92
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
@@ -250,26 +236,16 @@ function executeOperation(exeContext) {
|
|
|
250
236
|
* for fields that must be executed serially.
|
|
251
237
|
*/
|
|
252
238
|
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
|
|
253
|
-
let abortErrorThrown = false;
|
|
254
239
|
return (0, utils_1.promiseReduce)(fields, (results, [responseName, fieldNodes]) => {
|
|
255
240
|
const fieldPath = (0, utils_1.addPath)(path, responseName, parentType.name);
|
|
256
241
|
if (exeContext.signal?.aborted) {
|
|
257
|
-
|
|
258
|
-
return results;
|
|
242
|
+
throw exeContext.signal.reason;
|
|
259
243
|
}
|
|
260
244
|
return new value_or_promise_1.ValueOrPromise(() => executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath)).then(result => {
|
|
261
245
|
if (result === undefined) {
|
|
262
246
|
return results;
|
|
263
247
|
}
|
|
264
248
|
results[responseName] = result;
|
|
265
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
266
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
267
|
-
nodes: fieldNodes,
|
|
268
|
-
path: (0, utils_1.pathToArray)(fieldPath),
|
|
269
|
-
originalError: exeContext.signal?.reason,
|
|
270
|
-
}));
|
|
271
|
-
abortErrorThrown = true;
|
|
272
|
-
}
|
|
273
249
|
return results;
|
|
274
250
|
});
|
|
275
251
|
}, Object.create(null)).resolve();
|
|
@@ -281,12 +257,10 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
|
|
|
281
257
|
function executeFields(exeContext, parentType, sourceValue, path, fields, asyncPayloadRecord) {
|
|
282
258
|
const results = Object.create(null);
|
|
283
259
|
let containsPromise = false;
|
|
284
|
-
let abortErrorThrown = false;
|
|
285
260
|
try {
|
|
286
261
|
for (const [responseName, fieldNodes] of fields) {
|
|
287
262
|
if (exeContext.signal?.aborted) {
|
|
288
|
-
|
|
289
|
-
continue;
|
|
263
|
+
throw exeContext.signal.reason;
|
|
290
264
|
}
|
|
291
265
|
const fieldPath = (0, utils_1.addPath)(path, responseName, parentType.name);
|
|
292
266
|
const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath, asyncPayloadRecord);
|
|
@@ -296,14 +270,6 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
296
270
|
containsPromise = true;
|
|
297
271
|
}
|
|
298
272
|
}
|
|
299
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
300
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
301
|
-
nodes: fieldNodes,
|
|
302
|
-
path: (0, utils_1.pathToArray)(fieldPath),
|
|
303
|
-
originalError: exeContext.signal?.reason,
|
|
304
|
-
}));
|
|
305
|
-
abortErrorThrown = true;
|
|
306
|
-
}
|
|
307
273
|
}
|
|
308
274
|
}
|
|
309
275
|
catch (error) {
|
|
@@ -502,11 +468,6 @@ function getStreamValues(exeContext, fieldNodes, path) {
|
|
|
502
468
|
async function completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord) {
|
|
503
469
|
exeContext.signal?.addEventListener('abort', () => {
|
|
504
470
|
iterator.return?.();
|
|
505
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
506
|
-
nodes: fieldNodes,
|
|
507
|
-
path: (0, utils_1.pathToArray)(path),
|
|
508
|
-
originalError: exeContext.signal?.reason,
|
|
509
|
-
}));
|
|
510
471
|
});
|
|
511
472
|
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
|
|
512
473
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
@@ -830,15 +791,10 @@ function subscribe(args) {
|
|
|
830
791
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
831
792
|
}
|
|
832
793
|
exports.subscribe = subscribe;
|
|
833
|
-
function flattenIncrementalResults(incrementalResults
|
|
794
|
+
function flattenIncrementalResults(incrementalResults) {
|
|
834
795
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
835
796
|
let initialResultSent = false;
|
|
836
797
|
let done = false;
|
|
837
|
-
signal?.addEventListener('abort', () => {
|
|
838
|
-
done = true;
|
|
839
|
-
// we catch here to avoid unhandled promise rejection
|
|
840
|
-
subsequentIterator.throw?.(signal?.reason).catch(() => undefined);
|
|
841
|
-
});
|
|
842
798
|
return {
|
|
843
799
|
[Symbol.asyncIterator]() {
|
|
844
800
|
return this;
|
|
@@ -870,9 +826,9 @@ function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
870
826
|
};
|
|
871
827
|
}
|
|
872
828
|
exports.flattenIncrementalResults = flattenIncrementalResults;
|
|
873
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
829
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
874
830
|
if ('initialResult' in someExecutionResult) {
|
|
875
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
831
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
876
832
|
}
|
|
877
833
|
else {
|
|
878
834
|
yield someExecutionResult;
|
|
@@ -888,7 +844,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
888
844
|
// the GraphQL specification. The `execute` function provides the
|
|
889
845
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
890
846
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
891
|
-
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
847
|
+
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), (error) => {
|
|
892
848
|
const wrappedError = (0, utils_1.createGraphQLError)(error.message, {
|
|
893
849
|
originalError: error,
|
|
894
850
|
nodes: [exeContext.operation],
|
|
@@ -1185,16 +1141,20 @@ function getCompletedIncrementalResults(exeContext) {
|
|
|
1185
1141
|
}
|
|
1186
1142
|
function yieldSubsequentPayloads(exeContext) {
|
|
1187
1143
|
let isDone = false;
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1144
|
+
const abortPromise = new Promise((_, reject) => {
|
|
1145
|
+
exeContext.signal?.addEventListener('abort', () => {
|
|
1146
|
+
isDone = true;
|
|
1147
|
+
reject(exeContext.signal?.reason);
|
|
1148
|
+
});
|
|
1192
1149
|
});
|
|
1193
1150
|
async function next() {
|
|
1194
1151
|
if (isDone) {
|
|
1195
1152
|
return { value: undefined, done: true };
|
|
1196
1153
|
}
|
|
1197
|
-
await Promise.race(
|
|
1154
|
+
await Promise.race([
|
|
1155
|
+
abortPromise,
|
|
1156
|
+
...Array.from(exeContext.subsequentPayloads).map(p => p.promise),
|
|
1157
|
+
]);
|
|
1198
1158
|
if (isDone) {
|
|
1199
1159
|
// a different call to next has exhausted all payloads
|
|
1200
1160
|
return { value: undefined, done: true };
|
|
@@ -1249,11 +1209,10 @@ class DeferredFragmentRecord {
|
|
|
1249
1209
|
this._exeContext.subsequentPayloads.add(this);
|
|
1250
1210
|
this.isCompleted = false;
|
|
1251
1211
|
this.data = null;
|
|
1252
|
-
this.promise = new Promise(
|
|
1212
|
+
this.promise = new Promise(resolve => {
|
|
1253
1213
|
this._resolve = MaybePromise => {
|
|
1254
1214
|
resolve(MaybePromise);
|
|
1255
1215
|
};
|
|
1256
|
-
this._reject = reject;
|
|
1257
1216
|
}).then(data => {
|
|
1258
1217
|
this.data = data;
|
|
1259
1218
|
this.isCompleted = true;
|
|
@@ -1267,9 +1226,6 @@ class DeferredFragmentRecord {
|
|
|
1267
1226
|
}
|
|
1268
1227
|
this._resolve?.(data);
|
|
1269
1228
|
}
|
|
1270
|
-
cancel(reason) {
|
|
1271
|
-
this._reject?.(reason);
|
|
1272
|
-
}
|
|
1273
1229
|
}
|
|
1274
1230
|
class StreamRecord {
|
|
1275
1231
|
constructor(opts) {
|
|
@@ -1284,11 +1240,10 @@ class StreamRecord {
|
|
|
1284
1240
|
this._exeContext.subsequentPayloads.add(this);
|
|
1285
1241
|
this.isCompleted = false;
|
|
1286
1242
|
this.items = null;
|
|
1287
|
-
this.promise = new Promise(
|
|
1243
|
+
this.promise = new Promise(resolve => {
|
|
1288
1244
|
this._resolve = MaybePromise => {
|
|
1289
1245
|
resolve(MaybePromise);
|
|
1290
1246
|
};
|
|
1291
|
-
this._reject = reject;
|
|
1292
1247
|
}).then(items => {
|
|
1293
1248
|
this.items = items;
|
|
1294
1249
|
this.isCompleted = true;
|
|
@@ -1305,9 +1260,6 @@ class StreamRecord {
|
|
|
1305
1260
|
setIsCompletedIterator() {
|
|
1306
1261
|
this.isCompletedIterator = true;
|
|
1307
1262
|
}
|
|
1308
|
-
cancel(reason) {
|
|
1309
|
-
this._reject?.(reason);
|
|
1310
|
-
}
|
|
1311
1263
|
}
|
|
1312
1264
|
function isStreamPayload(asyncPayload) {
|
|
1313
1265
|
return asyncPayload.type === 'stream';
|
|
@@ -15,7 +15,7 @@ function normalizedExecutor(args) {
|
|
|
15
15
|
return new value_or_promise_1.ValueOrPromise(() => (0, execute_js_1.execute)(args))
|
|
16
16
|
.then((result) => {
|
|
17
17
|
if ('initialResult' in result) {
|
|
18
|
-
return (0, execute_js_1.flattenIncrementalResults)(result
|
|
18
|
+
return (0, execute_js_1.flattenIncrementalResults)(result);
|
|
19
19
|
}
|
|
20
20
|
return result;
|
|
21
21
|
})
|
|
@@ -12,7 +12,7 @@ async function promiseForObject(object, signal) {
|
|
|
12
12
|
const resolvedObject = Object.create(null);
|
|
13
13
|
await new Promise((resolve, reject) => {
|
|
14
14
|
signal?.addEventListener('abort', () => {
|
|
15
|
-
|
|
15
|
+
reject(signal.reason);
|
|
16
16
|
});
|
|
17
17
|
Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
18
18
|
resolvedObject[key] = await value;
|
package/esm/execution/execute.js
CHANGED
|
@@ -75,28 +75,14 @@ function executeImpl(exeContext) {
|
|
|
75
75
|
}
|
|
76
76
|
return initialResult;
|
|
77
77
|
}, (error) => {
|
|
78
|
+
if (exeContext.signal?.aborted) {
|
|
79
|
+
throw exeContext.signal.reason;
|
|
80
|
+
}
|
|
78
81
|
exeContext.errors.push(error);
|
|
79
82
|
return buildResponse(null, exeContext.errors);
|
|
80
83
|
})
|
|
81
84
|
.resolve();
|
|
82
|
-
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
let resolve;
|
|
86
|
-
let reject;
|
|
87
|
-
const abortP = new Promise((_resolve, _reject) => {
|
|
88
|
-
resolve = _resolve;
|
|
89
|
-
reject = _reject;
|
|
90
|
-
});
|
|
91
|
-
function abortListener() {
|
|
92
|
-
reject(exeContext.signal?.reason);
|
|
93
|
-
}
|
|
94
|
-
exeContext.signal.addEventListener('abort', abortListener);
|
|
95
|
-
result.then(() => {
|
|
96
|
-
exeContext.signal?.removeEventListener('abort', abortListener);
|
|
97
|
-
resolve();
|
|
98
|
-
});
|
|
99
|
-
return Promise.race([abortP, result]);
|
|
85
|
+
return result;
|
|
100
86
|
}
|
|
101
87
|
/**
|
|
102
88
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
@@ -243,26 +229,16 @@ function executeOperation(exeContext) {
|
|
|
243
229
|
* for fields that must be executed serially.
|
|
244
230
|
*/
|
|
245
231
|
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
|
|
246
|
-
let abortErrorThrown = false;
|
|
247
232
|
return promiseReduce(fields, (results, [responseName, fieldNodes]) => {
|
|
248
233
|
const fieldPath = addPath(path, responseName, parentType.name);
|
|
249
234
|
if (exeContext.signal?.aborted) {
|
|
250
|
-
|
|
251
|
-
return results;
|
|
235
|
+
throw exeContext.signal.reason;
|
|
252
236
|
}
|
|
253
237
|
return new ValueOrPromise(() => executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath)).then(result => {
|
|
254
238
|
if (result === undefined) {
|
|
255
239
|
return results;
|
|
256
240
|
}
|
|
257
241
|
results[responseName] = result;
|
|
258
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
259
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
260
|
-
nodes: fieldNodes,
|
|
261
|
-
path: pathToArray(fieldPath),
|
|
262
|
-
originalError: exeContext.signal?.reason,
|
|
263
|
-
}));
|
|
264
|
-
abortErrorThrown = true;
|
|
265
|
-
}
|
|
266
242
|
return results;
|
|
267
243
|
});
|
|
268
244
|
}, Object.create(null)).resolve();
|
|
@@ -274,12 +250,10 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
|
|
|
274
250
|
function executeFields(exeContext, parentType, sourceValue, path, fields, asyncPayloadRecord) {
|
|
275
251
|
const results = Object.create(null);
|
|
276
252
|
let containsPromise = false;
|
|
277
|
-
let abortErrorThrown = false;
|
|
278
253
|
try {
|
|
279
254
|
for (const [responseName, fieldNodes] of fields) {
|
|
280
255
|
if (exeContext.signal?.aborted) {
|
|
281
|
-
|
|
282
|
-
continue;
|
|
256
|
+
throw exeContext.signal.reason;
|
|
283
257
|
}
|
|
284
258
|
const fieldPath = addPath(path, responseName, parentType.name);
|
|
285
259
|
const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath, asyncPayloadRecord);
|
|
@@ -289,14 +263,6 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
289
263
|
containsPromise = true;
|
|
290
264
|
}
|
|
291
265
|
}
|
|
292
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
293
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
294
|
-
nodes: fieldNodes,
|
|
295
|
-
path: pathToArray(fieldPath),
|
|
296
|
-
originalError: exeContext.signal?.reason,
|
|
297
|
-
}));
|
|
298
|
-
abortErrorThrown = true;
|
|
299
|
-
}
|
|
300
266
|
}
|
|
301
267
|
}
|
|
302
268
|
catch (error) {
|
|
@@ -494,11 +460,6 @@ function getStreamValues(exeContext, fieldNodes, path) {
|
|
|
494
460
|
async function completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord) {
|
|
495
461
|
exeContext.signal?.addEventListener('abort', () => {
|
|
496
462
|
iterator.return?.();
|
|
497
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
498
|
-
nodes: fieldNodes,
|
|
499
|
-
path: pathToArray(path),
|
|
500
|
-
originalError: exeContext.signal?.reason,
|
|
501
|
-
}));
|
|
502
463
|
});
|
|
503
464
|
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
|
|
504
465
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
@@ -819,15 +780,10 @@ export function subscribe(args) {
|
|
|
819
780
|
}
|
|
820
781
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
821
782
|
}
|
|
822
|
-
export function flattenIncrementalResults(incrementalResults
|
|
783
|
+
export function flattenIncrementalResults(incrementalResults) {
|
|
823
784
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
824
785
|
let initialResultSent = false;
|
|
825
786
|
let done = false;
|
|
826
|
-
signal?.addEventListener('abort', () => {
|
|
827
|
-
done = true;
|
|
828
|
-
// we catch here to avoid unhandled promise rejection
|
|
829
|
-
subsequentIterator.throw?.(signal?.reason).catch(() => undefined);
|
|
830
|
-
});
|
|
831
787
|
return {
|
|
832
788
|
[Symbol.asyncIterator]() {
|
|
833
789
|
return this;
|
|
@@ -858,9 +814,9 @@ export function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
858
814
|
},
|
|
859
815
|
};
|
|
860
816
|
}
|
|
861
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
817
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
862
818
|
if ('initialResult' in someExecutionResult) {
|
|
863
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
819
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
864
820
|
}
|
|
865
821
|
else {
|
|
866
822
|
yield someExecutionResult;
|
|
@@ -876,7 +832,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
876
832
|
// the GraphQL specification. The `execute` function provides the
|
|
877
833
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
878
834
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
879
|
-
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
835
|
+
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), (error) => {
|
|
880
836
|
const wrappedError = createGraphQLError(error.message, {
|
|
881
837
|
originalError: error,
|
|
882
838
|
nodes: [exeContext.operation],
|
|
@@ -1173,16 +1129,20 @@ function getCompletedIncrementalResults(exeContext) {
|
|
|
1173
1129
|
}
|
|
1174
1130
|
function yieldSubsequentPayloads(exeContext) {
|
|
1175
1131
|
let isDone = false;
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1132
|
+
const abortPromise = new Promise((_, reject) => {
|
|
1133
|
+
exeContext.signal?.addEventListener('abort', () => {
|
|
1134
|
+
isDone = true;
|
|
1135
|
+
reject(exeContext.signal?.reason);
|
|
1136
|
+
});
|
|
1180
1137
|
});
|
|
1181
1138
|
async function next() {
|
|
1182
1139
|
if (isDone) {
|
|
1183
1140
|
return { value: undefined, done: true };
|
|
1184
1141
|
}
|
|
1185
|
-
await Promise.race(
|
|
1142
|
+
await Promise.race([
|
|
1143
|
+
abortPromise,
|
|
1144
|
+
...Array.from(exeContext.subsequentPayloads).map(p => p.promise),
|
|
1145
|
+
]);
|
|
1186
1146
|
if (isDone) {
|
|
1187
1147
|
// a different call to next has exhausted all payloads
|
|
1188
1148
|
return { value: undefined, done: true };
|
|
@@ -1237,11 +1197,10 @@ class DeferredFragmentRecord {
|
|
|
1237
1197
|
this._exeContext.subsequentPayloads.add(this);
|
|
1238
1198
|
this.isCompleted = false;
|
|
1239
1199
|
this.data = null;
|
|
1240
|
-
this.promise = new Promise(
|
|
1200
|
+
this.promise = new Promise(resolve => {
|
|
1241
1201
|
this._resolve = MaybePromise => {
|
|
1242
1202
|
resolve(MaybePromise);
|
|
1243
1203
|
};
|
|
1244
|
-
this._reject = reject;
|
|
1245
1204
|
}).then(data => {
|
|
1246
1205
|
this.data = data;
|
|
1247
1206
|
this.isCompleted = true;
|
|
@@ -1255,9 +1214,6 @@ class DeferredFragmentRecord {
|
|
|
1255
1214
|
}
|
|
1256
1215
|
this._resolve?.(data);
|
|
1257
1216
|
}
|
|
1258
|
-
cancel(reason) {
|
|
1259
|
-
this._reject?.(reason);
|
|
1260
|
-
}
|
|
1261
1217
|
}
|
|
1262
1218
|
class StreamRecord {
|
|
1263
1219
|
constructor(opts) {
|
|
@@ -1272,11 +1228,10 @@ class StreamRecord {
|
|
|
1272
1228
|
this._exeContext.subsequentPayloads.add(this);
|
|
1273
1229
|
this.isCompleted = false;
|
|
1274
1230
|
this.items = null;
|
|
1275
|
-
this.promise = new Promise(
|
|
1231
|
+
this.promise = new Promise(resolve => {
|
|
1276
1232
|
this._resolve = MaybePromise => {
|
|
1277
1233
|
resolve(MaybePromise);
|
|
1278
1234
|
};
|
|
1279
|
-
this._reject = reject;
|
|
1280
1235
|
}).then(items => {
|
|
1281
1236
|
this.items = items;
|
|
1282
1237
|
this.isCompleted = true;
|
|
@@ -1293,9 +1248,6 @@ class StreamRecord {
|
|
|
1293
1248
|
setIsCompletedIterator() {
|
|
1294
1249
|
this.isCompletedIterator = true;
|
|
1295
1250
|
}
|
|
1296
|
-
cancel(reason) {
|
|
1297
|
-
this._reject?.(reason);
|
|
1298
|
-
}
|
|
1299
1251
|
}
|
|
1300
1252
|
function isStreamPayload(asyncPayload) {
|
|
1301
1253
|
return asyncPayload.type === 'stream';
|
|
@@ -12,7 +12,7 @@ export function normalizedExecutor(args) {
|
|
|
12
12
|
return new ValueOrPromise(() => execute(args))
|
|
13
13
|
.then((result) => {
|
|
14
14
|
if ('initialResult' in result) {
|
|
15
|
-
return flattenIncrementalResults(result
|
|
15
|
+
return flattenIncrementalResults(result);
|
|
16
16
|
}
|
|
17
17
|
return result;
|
|
18
18
|
})
|
|
@@ -9,7 +9,7 @@ export async function promiseForObject(object, signal) {
|
|
|
9
9
|
const resolvedObject = Object.create(null);
|
|
10
10
|
await new Promise((resolve, reject) => {
|
|
11
11
|
signal?.addEventListener('abort', () => {
|
|
12
|
-
|
|
12
|
+
reject(signal.reason);
|
|
13
13
|
});
|
|
14
14
|
Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
15
15
|
resolvedObject[key] = await value;
|
package/package.json
CHANGED
|
@@ -204,7 +204,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
204
204
|
* Accepts an object with named arguments.
|
|
205
205
|
*/
|
|
206
206
|
export declare function subscribe<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>;
|
|
207
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
207
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
208
208
|
declare class DeferredFragmentRecord {
|
|
209
209
|
type: 'defer';
|
|
210
210
|
errors: Array<GraphQLError>;
|
|
@@ -216,7 +216,6 @@ declare class DeferredFragmentRecord {
|
|
|
216
216
|
isCompleted: boolean;
|
|
217
217
|
_exeContext: ExecutionContext;
|
|
218
218
|
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
219
|
-
_reject?: (reason: unknown) => void;
|
|
220
219
|
constructor(opts: {
|
|
221
220
|
label: string | undefined;
|
|
222
221
|
path: Path | undefined;
|
|
@@ -224,7 +223,6 @@ declare class DeferredFragmentRecord {
|
|
|
224
223
|
exeContext: ExecutionContext;
|
|
225
224
|
});
|
|
226
225
|
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
227
|
-
cancel(reason: unknown): void;
|
|
228
226
|
}
|
|
229
227
|
declare class StreamRecord {
|
|
230
228
|
type: 'stream';
|
|
@@ -239,7 +237,6 @@ declare class StreamRecord {
|
|
|
239
237
|
isCompleted: boolean;
|
|
240
238
|
_exeContext: ExecutionContext;
|
|
241
239
|
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
242
|
-
_reject?: (reason: unknown) => void;
|
|
243
240
|
constructor(opts: {
|
|
244
241
|
label: string | undefined;
|
|
245
242
|
path: Path | undefined;
|
|
@@ -249,7 +246,6 @@ declare class StreamRecord {
|
|
|
249
246
|
});
|
|
250
247
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
251
248
|
setIsCompletedIterator(): void;
|
|
252
|
-
cancel(reason: unknown): void;
|
|
253
249
|
}
|
|
254
250
|
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
255
251
|
/**
|
|
@@ -204,7 +204,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
204
204
|
* Accepts an object with named arguments.
|
|
205
205
|
*/
|
|
206
206
|
export declare function subscribe<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>;
|
|
207
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
207
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
208
208
|
declare class DeferredFragmentRecord {
|
|
209
209
|
type: 'defer';
|
|
210
210
|
errors: Array<GraphQLError>;
|
|
@@ -216,7 +216,6 @@ declare class DeferredFragmentRecord {
|
|
|
216
216
|
isCompleted: boolean;
|
|
217
217
|
_exeContext: ExecutionContext;
|
|
218
218
|
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
219
|
-
_reject?: (reason: unknown) => void;
|
|
220
219
|
constructor(opts: {
|
|
221
220
|
label: string | undefined;
|
|
222
221
|
path: Path | undefined;
|
|
@@ -224,7 +223,6 @@ declare class DeferredFragmentRecord {
|
|
|
224
223
|
exeContext: ExecutionContext;
|
|
225
224
|
});
|
|
226
225
|
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
227
|
-
cancel(reason: unknown): void;
|
|
228
226
|
}
|
|
229
227
|
declare class StreamRecord {
|
|
230
228
|
type: 'stream';
|
|
@@ -239,7 +237,6 @@ declare class StreamRecord {
|
|
|
239
237
|
isCompleted: boolean;
|
|
240
238
|
_exeContext: ExecutionContext;
|
|
241
239
|
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
242
|
-
_reject?: (reason: unknown) => void;
|
|
243
240
|
constructor(opts: {
|
|
244
241
|
label: string | undefined;
|
|
245
242
|
path: Path | undefined;
|
|
@@ -249,7 +246,6 @@ declare class StreamRecord {
|
|
|
249
246
|
});
|
|
250
247
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
251
248
|
setIsCompletedIterator(): void;
|
|
252
|
-
cancel(reason: unknown): void;
|
|
253
249
|
}
|
|
254
250
|
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
255
251
|
/**
|