@graphql-tools/executor 1.1.0-alpha-20230522102854-674fb2cd → 1.1.0-alpha-20230523100937-3794de50
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 +24 -58
- package/cjs/execution/normalizedExecutor.js +1 -1
- package/cjs/execution/promiseForObject.js +4 -9
- package/esm/execution/execute.js +25 -59
- package/esm/execution/normalizedExecutor.js +1 -1
- package/esm/execution/promiseForObject.js +4 -9
- package/package.json +1 -1
- package/typings/execution/execute.d.cts +2 -5
- package/typings/execution/execute.d.ts +2 -5
- package/typings/execution/promiseForObject.d.cts +1 -1
- package/typings/execution/promiseForObject.d.ts +1 -1
package/cjs/execution/execute.js
CHANGED
|
@@ -135,7 +135,7 @@ exports.getFragmentsFromDocument = (0, utils_1.memoize1)(function getFragmentsFr
|
|
|
135
135
|
* @internal
|
|
136
136
|
*/
|
|
137
137
|
function buildExecutionContext(args) {
|
|
138
|
-
const { schema, document, rootValue, contextValue, variableValues: rawVariableValues, operationName, fieldResolver, typeResolver, subscribeFieldResolver,
|
|
138
|
+
const { schema, document, rootValue, contextValue, variableValues: rawVariableValues, operationName, fieldResolver, typeResolver, subscribeFieldResolver, } = args;
|
|
139
139
|
// If the schema used for execution is invalid, throw an error.
|
|
140
140
|
(0, graphql_1.assertValidSchema)(schema);
|
|
141
141
|
const fragments = (0, exports.getFragmentsFromDocument)(document);
|
|
@@ -184,7 +184,6 @@ function buildExecutionContext(args) {
|
|
|
184
184
|
subscribeFieldResolver: subscribeFieldResolver ?? exports.defaultFieldResolver,
|
|
185
185
|
subsequentPayloads: new Set(),
|
|
186
186
|
errors: [],
|
|
187
|
-
signal,
|
|
188
187
|
};
|
|
189
188
|
}
|
|
190
189
|
exports.buildExecutionContext = buildExecutionContext;
|
|
@@ -227,26 +226,13 @@ function executeOperation(exeContext) {
|
|
|
227
226
|
* for fields that must be executed serially.
|
|
228
227
|
*/
|
|
229
228
|
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
|
|
230
|
-
let abortErrorThrown = false;
|
|
231
229
|
return (0, utils_1.promiseReduce)(fields, (results, [responseName, fieldNodes]) => {
|
|
232
230
|
const fieldPath = (0, utils_1.addPath)(path, responseName, parentType.name);
|
|
233
|
-
if (exeContext.signal?.aborted) {
|
|
234
|
-
results[responseName] = null;
|
|
235
|
-
return results;
|
|
236
|
-
}
|
|
237
231
|
return new value_or_promise_1.ValueOrPromise(() => executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath)).then(result => {
|
|
238
232
|
if (result === undefined) {
|
|
239
233
|
return results;
|
|
240
234
|
}
|
|
241
235
|
results[responseName] = result;
|
|
242
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
243
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
244
|
-
nodes: fieldNodes,
|
|
245
|
-
path: (0, utils_1.pathToArray)(fieldPath),
|
|
246
|
-
originalError: exeContext.signal?.reason,
|
|
247
|
-
}));
|
|
248
|
-
abortErrorThrown = true;
|
|
249
|
-
}
|
|
250
236
|
return results;
|
|
251
237
|
});
|
|
252
238
|
}, Object.create(null)).resolve();
|
|
@@ -258,13 +244,8 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
|
|
|
258
244
|
function executeFields(exeContext, parentType, sourceValue, path, fields, asyncPayloadRecord) {
|
|
259
245
|
const results = Object.create(null);
|
|
260
246
|
let containsPromise = false;
|
|
261
|
-
let abortErrorThrown = false;
|
|
262
247
|
try {
|
|
263
248
|
for (const [responseName, fieldNodes] of fields) {
|
|
264
|
-
if (exeContext.signal?.aborted) {
|
|
265
|
-
results[responseName] = null;
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
249
|
const fieldPath = (0, utils_1.addPath)(path, responseName, parentType.name);
|
|
269
250
|
const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath, asyncPayloadRecord);
|
|
270
251
|
if (result !== undefined) {
|
|
@@ -273,20 +254,12 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
273
254
|
containsPromise = true;
|
|
274
255
|
}
|
|
275
256
|
}
|
|
276
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
277
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
278
|
-
nodes: fieldNodes,
|
|
279
|
-
path: (0, utils_1.pathToArray)(fieldPath),
|
|
280
|
-
originalError: exeContext.signal?.reason,
|
|
281
|
-
}));
|
|
282
|
-
abortErrorThrown = true;
|
|
283
|
-
}
|
|
284
257
|
}
|
|
285
258
|
}
|
|
286
259
|
catch (error) {
|
|
287
260
|
if (containsPromise) {
|
|
288
261
|
// Ensure that any promises returned by other fields are handled, as they may also reject.
|
|
289
|
-
return (0, promiseForObject_js_1.promiseForObject)(results
|
|
262
|
+
return (0, promiseForObject_js_1.promiseForObject)(results).finally(() => {
|
|
290
263
|
throw error;
|
|
291
264
|
});
|
|
292
265
|
}
|
|
@@ -299,7 +272,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
299
272
|
// Otherwise, results is a map from field name to the result of resolving that
|
|
300
273
|
// field, which is possibly a promise. Return a promise that will return this
|
|
301
274
|
// same map, but with any promises replaced with the values they resolved to.
|
|
302
|
-
return (0, promiseForObject_js_1.promiseForObject)(results
|
|
275
|
+
return (0, promiseForObject_js_1.promiseForObject)(results);
|
|
303
276
|
}
|
|
304
277
|
/**
|
|
305
278
|
* Implements the "Executing fields" section of the spec
|
|
@@ -477,14 +450,6 @@ function getStreamValues(exeContext, fieldNodes, path) {
|
|
|
477
450
|
* recursively until all the results are completed.
|
|
478
451
|
*/
|
|
479
452
|
async function completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord) {
|
|
480
|
-
exeContext.signal?.addEventListener('abort', () => {
|
|
481
|
-
iterator.return?.();
|
|
482
|
-
exeContext.errors.push((0, utils_1.createGraphQLError)('Execution aborted', {
|
|
483
|
-
nodes: fieldNodes,
|
|
484
|
-
path: (0, utils_1.pathToArray)(path),
|
|
485
|
-
originalError: exeContext.signal?.reason,
|
|
486
|
-
}));
|
|
487
|
-
});
|
|
488
453
|
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
|
|
489
454
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
490
455
|
let containsPromise = false;
|
|
@@ -592,7 +557,20 @@ function completeListItemValue(item, completedResults, errors, exeContext, itemT
|
|
|
592
557
|
* null if serialization is not possible.
|
|
593
558
|
*/
|
|
594
559
|
function completeLeafValue(returnType, result) {
|
|
595
|
-
|
|
560
|
+
let serializedResult;
|
|
561
|
+
// Note: We transform GraphQLError to Error in order to be consistent with
|
|
562
|
+
// how non-null checks work later on.
|
|
563
|
+
// See https://github.com/kamilkisiela/graphql-hive/pull/2299
|
|
564
|
+
// See https://github.com/n1ru4l/envelop/issues/1808
|
|
565
|
+
try {
|
|
566
|
+
serializedResult = returnType.serialize(result);
|
|
567
|
+
}
|
|
568
|
+
catch (err) {
|
|
569
|
+
if (err instanceof graphql_1.GraphQLError) {
|
|
570
|
+
throw new Error(err.message);
|
|
571
|
+
}
|
|
572
|
+
throw err;
|
|
573
|
+
}
|
|
596
574
|
if (serializedResult == null) {
|
|
597
575
|
throw new Error(`Expected \`${(0, utils_1.inspect)(returnType)}.serialize(${(0, utils_1.inspect)(result)})\` to ` +
|
|
598
576
|
`return non-nullable value, returned: ${(0, utils_1.inspect)(serializedResult)}`);
|
|
@@ -794,14 +772,10 @@ function subscribe(args) {
|
|
|
794
772
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
795
773
|
}
|
|
796
774
|
exports.subscribe = subscribe;
|
|
797
|
-
function flattenIncrementalResults(incrementalResults
|
|
775
|
+
function flattenIncrementalResults(incrementalResults) {
|
|
798
776
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
799
777
|
let initialResultSent = false;
|
|
800
778
|
let done = false;
|
|
801
|
-
signal?.addEventListener('abort', () => {
|
|
802
|
-
done = true;
|
|
803
|
-
subsequentIterator.throw?.(signal?.reason);
|
|
804
|
-
});
|
|
805
779
|
return {
|
|
806
780
|
[Symbol.asyncIterator]() {
|
|
807
781
|
return this;
|
|
@@ -833,9 +807,9 @@ function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
833
807
|
};
|
|
834
808
|
}
|
|
835
809
|
exports.flattenIncrementalResults = flattenIncrementalResults;
|
|
836
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
810
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
837
811
|
if ('initialResult' in someExecutionResult) {
|
|
838
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
812
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
839
813
|
}
|
|
840
814
|
else {
|
|
841
815
|
yield someExecutionResult;
|
|
@@ -851,7 +825,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
851
825
|
// the GraphQL specification. The `execute` function provides the
|
|
852
826
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
853
827
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
854
|
-
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
828
|
+
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), async function* (error) {
|
|
855
829
|
const wrappedError = (0, utils_1.createGraphQLError)(error.message, {
|
|
856
830
|
originalError: error,
|
|
857
831
|
nodes: [exeContext.operation],
|
|
@@ -907,13 +881,13 @@ function executeSubscription(exeContext) {
|
|
|
907
881
|
throw (0, graphql_1.locatedError)(error, fieldNodes, (0, utils_1.pathToArray)(path));
|
|
908
882
|
});
|
|
909
883
|
}
|
|
910
|
-
return assertEventStream(result
|
|
884
|
+
return assertEventStream(result);
|
|
911
885
|
}
|
|
912
886
|
catch (error) {
|
|
913
887
|
throw (0, graphql_1.locatedError)(error, fieldNodes, (0, utils_1.pathToArray)(path));
|
|
914
888
|
}
|
|
915
889
|
}
|
|
916
|
-
function assertEventStream(result
|
|
890
|
+
function assertEventStream(result) {
|
|
917
891
|
if (result instanceof Error) {
|
|
918
892
|
throw result;
|
|
919
893
|
}
|
|
@@ -921,15 +895,7 @@ function assertEventStream(result, signal) {
|
|
|
921
895
|
if (!(0, utils_1.isAsyncIterable)(result)) {
|
|
922
896
|
throw (0, utils_1.createGraphQLError)('Subscription field must return Async Iterable. ' + `Received: ${(0, utils_1.inspect)(result)}.`);
|
|
923
897
|
}
|
|
924
|
-
return
|
|
925
|
-
[Symbol.asyncIterator]() {
|
|
926
|
-
const asyncIterator = result[Symbol.asyncIterator]();
|
|
927
|
-
signal?.addEventListener('abort', () => {
|
|
928
|
-
asyncIterator.return?.();
|
|
929
|
-
});
|
|
930
|
-
return asyncIterator;
|
|
931
|
-
},
|
|
932
|
-
};
|
|
898
|
+
return result;
|
|
933
899
|
}
|
|
934
900
|
function executeDeferredFragment(exeContext, parentType, sourceValue, fields, label, path, parentContext) {
|
|
935
901
|
const asyncPayloadRecord = new DeferredFragmentRecord({
|
|
@@ -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
|
})
|
|
@@ -8,16 +8,11 @@ exports.promiseForObject = void 0;
|
|
|
8
8
|
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
9
9
|
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
10
10
|
*/
|
|
11
|
-
async function promiseForObject(object
|
|
11
|
+
async function promiseForObject(object) {
|
|
12
12
|
const resolvedObject = Object.create(null);
|
|
13
|
-
await
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
18
|
-
resolvedObject[key] = await value;
|
|
19
|
-
})).then(() => resolve(), reject);
|
|
20
|
-
});
|
|
13
|
+
await Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
14
|
+
resolvedObject[key] = await value;
|
|
15
|
+
}));
|
|
21
16
|
return resolvedObject;
|
|
22
17
|
}
|
|
23
18
|
exports.promiseForObject = promiseForObject;
|
package/esm/execution/execute.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { locatedError, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, getDirectiveValues, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql';
|
|
1
|
+
import { locatedError, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, getDirectiveValues, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, GraphQLError, } from 'graphql';
|
|
2
2
|
import { createGraphQLError, inspect, isAsyncIterable, isIterableObject, isObjectLike, isPromise, pathToArray, addPath, getArgumentValues, promiseReduce, memoize3, getDefinedRootType, mapAsyncIterator, GraphQLStreamDirective, collectFields, collectSubFields as _collectSubfields, memoize1, } from '@graphql-tools/utils';
|
|
3
3
|
import { getVariableValues } from './values.js';
|
|
4
4
|
import { promiseForObject } from './promiseForObject.js';
|
|
@@ -129,7 +129,7 @@ export const getFragmentsFromDocument = memoize1(function getFragmentsFromDocume
|
|
|
129
129
|
* @internal
|
|
130
130
|
*/
|
|
131
131
|
export function buildExecutionContext(args) {
|
|
132
|
-
const { schema, document, rootValue, contextValue, variableValues: rawVariableValues, operationName, fieldResolver, typeResolver, subscribeFieldResolver,
|
|
132
|
+
const { schema, document, rootValue, contextValue, variableValues: rawVariableValues, operationName, fieldResolver, typeResolver, subscribeFieldResolver, } = args;
|
|
133
133
|
// If the schema used for execution is invalid, throw an error.
|
|
134
134
|
assertValidSchema(schema);
|
|
135
135
|
const fragments = getFragmentsFromDocument(document);
|
|
@@ -178,7 +178,6 @@ export function buildExecutionContext(args) {
|
|
|
178
178
|
subscribeFieldResolver: subscribeFieldResolver ?? defaultFieldResolver,
|
|
179
179
|
subsequentPayloads: new Set(),
|
|
180
180
|
errors: [],
|
|
181
|
-
signal,
|
|
182
181
|
};
|
|
183
182
|
}
|
|
184
183
|
function buildPerEventExecutionContext(exeContext, payload) {
|
|
@@ -220,26 +219,13 @@ function executeOperation(exeContext) {
|
|
|
220
219
|
* for fields that must be executed serially.
|
|
221
220
|
*/
|
|
222
221
|
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
|
|
223
|
-
let abortErrorThrown = false;
|
|
224
222
|
return promiseReduce(fields, (results, [responseName, fieldNodes]) => {
|
|
225
223
|
const fieldPath = addPath(path, responseName, parentType.name);
|
|
226
|
-
if (exeContext.signal?.aborted) {
|
|
227
|
-
results[responseName] = null;
|
|
228
|
-
return results;
|
|
229
|
-
}
|
|
230
224
|
return new ValueOrPromise(() => executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath)).then(result => {
|
|
231
225
|
if (result === undefined) {
|
|
232
226
|
return results;
|
|
233
227
|
}
|
|
234
228
|
results[responseName] = result;
|
|
235
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
236
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
237
|
-
nodes: fieldNodes,
|
|
238
|
-
path: pathToArray(fieldPath),
|
|
239
|
-
originalError: exeContext.signal?.reason,
|
|
240
|
-
}));
|
|
241
|
-
abortErrorThrown = true;
|
|
242
|
-
}
|
|
243
229
|
return results;
|
|
244
230
|
});
|
|
245
231
|
}, Object.create(null)).resolve();
|
|
@@ -251,13 +237,8 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
|
|
|
251
237
|
function executeFields(exeContext, parentType, sourceValue, path, fields, asyncPayloadRecord) {
|
|
252
238
|
const results = Object.create(null);
|
|
253
239
|
let containsPromise = false;
|
|
254
|
-
let abortErrorThrown = false;
|
|
255
240
|
try {
|
|
256
241
|
for (const [responseName, fieldNodes] of fields) {
|
|
257
|
-
if (exeContext.signal?.aborted) {
|
|
258
|
-
results[responseName] = null;
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
242
|
const fieldPath = addPath(path, responseName, parentType.name);
|
|
262
243
|
const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath, asyncPayloadRecord);
|
|
263
244
|
if (result !== undefined) {
|
|
@@ -266,20 +247,12 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
266
247
|
containsPromise = true;
|
|
267
248
|
}
|
|
268
249
|
}
|
|
269
|
-
if (exeContext.signal?.aborted && !abortErrorThrown) {
|
|
270
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
271
|
-
nodes: fieldNodes,
|
|
272
|
-
path: pathToArray(fieldPath),
|
|
273
|
-
originalError: exeContext.signal?.reason,
|
|
274
|
-
}));
|
|
275
|
-
abortErrorThrown = true;
|
|
276
|
-
}
|
|
277
250
|
}
|
|
278
251
|
}
|
|
279
252
|
catch (error) {
|
|
280
253
|
if (containsPromise) {
|
|
281
254
|
// Ensure that any promises returned by other fields are handled, as they may also reject.
|
|
282
|
-
return promiseForObject(results
|
|
255
|
+
return promiseForObject(results).finally(() => {
|
|
283
256
|
throw error;
|
|
284
257
|
});
|
|
285
258
|
}
|
|
@@ -292,7 +265,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
292
265
|
// Otherwise, results is a map from field name to the result of resolving that
|
|
293
266
|
// field, which is possibly a promise. Return a promise that will return this
|
|
294
267
|
// same map, but with any promises replaced with the values they resolved to.
|
|
295
|
-
return promiseForObject(results
|
|
268
|
+
return promiseForObject(results);
|
|
296
269
|
}
|
|
297
270
|
/**
|
|
298
271
|
* Implements the "Executing fields" section of the spec
|
|
@@ -469,14 +442,6 @@ function getStreamValues(exeContext, fieldNodes, path) {
|
|
|
469
442
|
* recursively until all the results are completed.
|
|
470
443
|
*/
|
|
471
444
|
async function completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord) {
|
|
472
|
-
exeContext.signal?.addEventListener('abort', () => {
|
|
473
|
-
iterator.return?.();
|
|
474
|
-
exeContext.errors.push(createGraphQLError('Execution aborted', {
|
|
475
|
-
nodes: fieldNodes,
|
|
476
|
-
path: pathToArray(path),
|
|
477
|
-
originalError: exeContext.signal?.reason,
|
|
478
|
-
}));
|
|
479
|
-
});
|
|
480
445
|
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
|
|
481
446
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
482
447
|
let containsPromise = false;
|
|
@@ -584,7 +549,20 @@ function completeListItemValue(item, completedResults, errors, exeContext, itemT
|
|
|
584
549
|
* null if serialization is not possible.
|
|
585
550
|
*/
|
|
586
551
|
function completeLeafValue(returnType, result) {
|
|
587
|
-
|
|
552
|
+
let serializedResult;
|
|
553
|
+
// Note: We transform GraphQLError to Error in order to be consistent with
|
|
554
|
+
// how non-null checks work later on.
|
|
555
|
+
// See https://github.com/kamilkisiela/graphql-hive/pull/2299
|
|
556
|
+
// See https://github.com/n1ru4l/envelop/issues/1808
|
|
557
|
+
try {
|
|
558
|
+
serializedResult = returnType.serialize(result);
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
if (err instanceof GraphQLError) {
|
|
562
|
+
throw new Error(err.message);
|
|
563
|
+
}
|
|
564
|
+
throw err;
|
|
565
|
+
}
|
|
588
566
|
if (serializedResult == null) {
|
|
589
567
|
throw new Error(`Expected \`${inspect(returnType)}.serialize(${inspect(result)})\` to ` +
|
|
590
568
|
`return non-nullable value, returned: ${inspect(serializedResult)}`);
|
|
@@ -783,14 +761,10 @@ export function subscribe(args) {
|
|
|
783
761
|
}
|
|
784
762
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
785
763
|
}
|
|
786
|
-
export function flattenIncrementalResults(incrementalResults
|
|
764
|
+
export function flattenIncrementalResults(incrementalResults) {
|
|
787
765
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
788
766
|
let initialResultSent = false;
|
|
789
767
|
let done = false;
|
|
790
|
-
signal?.addEventListener('abort', () => {
|
|
791
|
-
done = true;
|
|
792
|
-
subsequentIterator.throw?.(signal?.reason);
|
|
793
|
-
});
|
|
794
768
|
return {
|
|
795
769
|
[Symbol.asyncIterator]() {
|
|
796
770
|
return this;
|
|
@@ -821,9 +795,9 @@ export function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
821
795
|
},
|
|
822
796
|
};
|
|
823
797
|
}
|
|
824
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
798
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
825
799
|
if ('initialResult' in someExecutionResult) {
|
|
826
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
800
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
827
801
|
}
|
|
828
802
|
else {
|
|
829
803
|
yield someExecutionResult;
|
|
@@ -839,7 +813,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
839
813
|
// the GraphQL specification. The `execute` function provides the
|
|
840
814
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
841
815
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
842
|
-
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
816
|
+
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), async function* (error) {
|
|
843
817
|
const wrappedError = createGraphQLError(error.message, {
|
|
844
818
|
originalError: error,
|
|
845
819
|
nodes: [exeContext.operation],
|
|
@@ -895,13 +869,13 @@ function executeSubscription(exeContext) {
|
|
|
895
869
|
throw locatedError(error, fieldNodes, pathToArray(path));
|
|
896
870
|
});
|
|
897
871
|
}
|
|
898
|
-
return assertEventStream(result
|
|
872
|
+
return assertEventStream(result);
|
|
899
873
|
}
|
|
900
874
|
catch (error) {
|
|
901
875
|
throw locatedError(error, fieldNodes, pathToArray(path));
|
|
902
876
|
}
|
|
903
877
|
}
|
|
904
|
-
function assertEventStream(result
|
|
878
|
+
function assertEventStream(result) {
|
|
905
879
|
if (result instanceof Error) {
|
|
906
880
|
throw result;
|
|
907
881
|
}
|
|
@@ -909,15 +883,7 @@ function assertEventStream(result, signal) {
|
|
|
909
883
|
if (!isAsyncIterable(result)) {
|
|
910
884
|
throw createGraphQLError('Subscription field must return Async Iterable. ' + `Received: ${inspect(result)}.`);
|
|
911
885
|
}
|
|
912
|
-
return
|
|
913
|
-
[Symbol.asyncIterator]() {
|
|
914
|
-
const asyncIterator = result[Symbol.asyncIterator]();
|
|
915
|
-
signal?.addEventListener('abort', () => {
|
|
916
|
-
asyncIterator.return?.();
|
|
917
|
-
});
|
|
918
|
-
return asyncIterator;
|
|
919
|
-
},
|
|
920
|
-
};
|
|
886
|
+
return result;
|
|
921
887
|
}
|
|
922
888
|
function executeDeferredFragment(exeContext, parentType, sourceValue, fields, label, path, parentContext) {
|
|
923
889
|
const asyncPayloadRecord = new DeferredFragmentRecord({
|
|
@@ -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
|
})
|
|
@@ -5,15 +5,10 @@
|
|
|
5
5
|
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
6
6
|
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
7
7
|
*/
|
|
8
|
-
export async function promiseForObject(object
|
|
8
|
+
export async function promiseForObject(object) {
|
|
9
9
|
const resolvedObject = Object.create(null);
|
|
10
|
-
await
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
15
|
-
resolvedObject[key] = await value;
|
|
16
|
-
})).then(() => resolve(), reject);
|
|
17
|
-
});
|
|
10
|
+
await Promise.all(Object.entries(object).map(async ([key, value]) => {
|
|
11
|
+
resolvedObject[key] = await value;
|
|
12
|
+
}));
|
|
18
13
|
return resolvedObject;
|
|
19
14
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema, DocumentNode } from 'graphql';
|
|
2
|
-
import type { GraphQLError } from 'graphql';
|
|
1
|
+
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema, DocumentNode, GraphQLError } from 'graphql';
|
|
3
2
|
import { Path, Maybe, MaybePromise } from '@graphql-tools/utils';
|
|
4
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
4
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
@@ -44,7 +43,6 @@ export interface ExecutionContext<TVariables = any, TContext = any> {
|
|
|
44
43
|
subscribeFieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
45
44
|
errors: Array<GraphQLError>;
|
|
46
45
|
subsequentPayloads: Set<AsyncPayloadRecord>;
|
|
47
|
-
signal?: AbortSignal;
|
|
48
46
|
}
|
|
49
47
|
export interface FormattedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
50
48
|
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
@@ -109,7 +107,6 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
109
107
|
fieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>;
|
|
110
108
|
typeResolver?: Maybe<GraphQLTypeResolver<any, TContext>>;
|
|
111
109
|
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>;
|
|
112
|
-
signal?: AbortSignal;
|
|
113
110
|
}
|
|
114
111
|
/**
|
|
115
112
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
@@ -205,7 +202,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
205
202
|
* Accepts an object with named arguments.
|
|
206
203
|
*/
|
|
207
204
|
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>>;
|
|
208
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
205
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
209
206
|
declare class DeferredFragmentRecord {
|
|
210
207
|
type: 'defer';
|
|
211
208
|
errors: Array<GraphQLError>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema, DocumentNode } from 'graphql';
|
|
2
|
-
import type { GraphQLError } from 'graphql';
|
|
1
|
+
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema, DocumentNode, GraphQLError } from 'graphql';
|
|
3
2
|
import { Path, Maybe, MaybePromise } from '@graphql-tools/utils';
|
|
4
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
4
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
@@ -44,7 +43,6 @@ export interface ExecutionContext<TVariables = any, TContext = any> {
|
|
|
44
43
|
subscribeFieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
45
44
|
errors: Array<GraphQLError>;
|
|
46
45
|
subsequentPayloads: Set<AsyncPayloadRecord>;
|
|
47
|
-
signal?: AbortSignal;
|
|
48
46
|
}
|
|
49
47
|
export interface FormattedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
50
48
|
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
@@ -109,7 +107,6 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
109
107
|
fieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>;
|
|
110
108
|
typeResolver?: Maybe<GraphQLTypeResolver<any, TContext>>;
|
|
111
109
|
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>;
|
|
112
|
-
signal?: AbortSignal;
|
|
113
110
|
}
|
|
114
111
|
/**
|
|
115
112
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
@@ -205,7 +202,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
205
202
|
* Accepts an object with named arguments.
|
|
206
203
|
*/
|
|
207
204
|
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>>;
|
|
208
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
205
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
209
206
|
declare class DeferredFragmentRecord {
|
|
210
207
|
type: 'defer';
|
|
211
208
|
errors: Array<GraphQLError>;
|
|
@@ -8,5 +8,5 @@ type ResolvedObject<TData> = {
|
|
|
8
8
|
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
9
9
|
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
10
10
|
*/
|
|
11
|
-
export declare function promiseForObject<TData>(object: TData
|
|
11
|
+
export declare function promiseForObject<TData>(object: TData): Promise<ResolvedObject<TData>>;
|
|
12
12
|
export {};
|
|
@@ -8,5 +8,5 @@ type ResolvedObject<TData> = {
|
|
|
8
8
|
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
9
9
|
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
10
10
|
*/
|
|
11
|
-
export declare function promiseForObject<TData>(object: TData
|
|
11
|
+
export declare function promiseForObject<TData>(object: TData): Promise<ResolvedObject<TData>>;
|
|
12
12
|
export {};
|