@graphql-tools/executor 2.0.5 → 3.0.0-alpha-20261015151226-5868300779ac4a46f260b4a5fd3fd669c4d7cba8
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 +58 -48
- package/cjs/execution/normalizedExecutor.js +3 -2
- package/cjs/execution/validateInputValue.js +2 -2
- package/cjs/execution/values.js +5 -5
- package/esm/execution/execute.js +38 -29
- package/esm/execution/normalizedExecutor.js +2 -2
- package/esm/execution/validateInputValue.js +3 -3
- package/esm/execution/values.js +7 -7
- package/package.json +5 -4
- package/typings/execution/execute.d.cts +4 -3
- package/typings/execution/execute.d.ts +4 -3
- package/typings/execution/normalizedExecutor.d.cts +3 -3
- package/typings/execution/normalizedExecutor.d.ts +3 -3
package/cjs/execution/execute.js
CHANGED
|
@@ -11,7 +11,9 @@ exports.isIncrementalResults = isIncrementalResults;
|
|
|
11
11
|
exports.flattenIncrementalResults = flattenIncrementalResults;
|
|
12
12
|
exports.getFieldDef = getFieldDef;
|
|
13
13
|
exports.isIncrementalResult = isIncrementalResult;
|
|
14
|
+
const tslib_1 = require("tslib");
|
|
14
15
|
const graphql_1 = require("graphql");
|
|
16
|
+
const weak_js_1 = tslib_1.__importDefault(require("memoizee/weak.js"));
|
|
15
17
|
const utils_1 = require("@graphql-tools/utils");
|
|
16
18
|
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
17
19
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
@@ -25,7 +27,16 @@ const values_js_1 = require("./values.js");
|
|
|
25
27
|
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
26
28
|
* saves overhead when resolving lists of values.
|
|
27
29
|
*/
|
|
28
|
-
const
|
|
30
|
+
const collectSubfieldsMemo = (0, weak_js_1.default)(function collectSubfieldsExeContext(exeContext) {
|
|
31
|
+
return (0, weak_js_1.default)(function collectSubfieldsReturnType(returnType) {
|
|
32
|
+
return (0, weak_js_1.default)(function collectSubfieldsFieldNodes(fieldNodes) {
|
|
33
|
+
return (0, utils_1.collectSubFields)(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
function collectSubfields(exeContext, returnType, fieldNodes) {
|
|
38
|
+
return collectSubfieldsMemo(exeContext)(returnType)(fieldNodes);
|
|
39
|
+
}
|
|
29
40
|
/**
|
|
30
41
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
31
42
|
* including `@defer` and `@stream` as proposed in
|
|
@@ -105,7 +116,7 @@ function executeImpl(exeContext) {
|
|
|
105
116
|
function executeSync(args) {
|
|
106
117
|
const result = execute(args);
|
|
107
118
|
// Assert that the execution was synchronous.
|
|
108
|
-
if ((0,
|
|
119
|
+
if ((0, promise_helpers_1.isPromise)(result) || 'initialResult' in result) {
|
|
109
120
|
throw new Error('GraphQL execution failed to complete synchronously.');
|
|
110
121
|
}
|
|
111
122
|
return result;
|
|
@@ -130,7 +141,7 @@ function assertValidExecutionArguments(schema, document, rawVariableValues) {
|
|
|
130
141
|
// Variables, if provided, must be an object.
|
|
131
142
|
console.assert(rawVariableValues == null || (0, utils_1.isObjectLike)(rawVariableValues), 'Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided.');
|
|
132
143
|
}
|
|
133
|
-
exports.getFragmentsFromDocument = (0,
|
|
144
|
+
exports.getFragmentsFromDocument = (0, weak_js_1.default)(function getFragmentsFromDocument(document) {
|
|
134
145
|
const fragments = Object.create(null);
|
|
135
146
|
for (const definition of document.definitions) {
|
|
136
147
|
if (definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
|
|
@@ -161,7 +172,7 @@ function buildExecutionContext(args) {
|
|
|
161
172
|
if (operationName == null) {
|
|
162
173
|
if (operation !== undefined) {
|
|
163
174
|
return [
|
|
164
|
-
|
|
175
|
+
new graphql_1.GraphQLError('Must provide operation name if query contains multiple operations.', {
|
|
165
176
|
extensions: {
|
|
166
177
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
167
178
|
},
|
|
@@ -181,7 +192,7 @@ function buildExecutionContext(args) {
|
|
|
181
192
|
if (operation == null) {
|
|
182
193
|
if (operationName != null) {
|
|
183
194
|
return [
|
|
184
|
-
|
|
195
|
+
new graphql_1.GraphQLError(`Unknown operation named "${operationName}".`, {
|
|
185
196
|
extensions: {
|
|
186
197
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
187
198
|
},
|
|
@@ -189,7 +200,7 @@ function buildExecutionContext(args) {
|
|
|
189
200
|
];
|
|
190
201
|
}
|
|
191
202
|
return [
|
|
192
|
-
|
|
203
|
+
new graphql_1.GraphQLError('Must provide an operation.', {
|
|
193
204
|
extensions: {
|
|
194
205
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
195
206
|
},
|
|
@@ -210,7 +221,7 @@ function buildExecutionContext(args) {
|
|
|
210
221
|
let signalPromise;
|
|
211
222
|
if (signal) {
|
|
212
223
|
const listeners = new Set();
|
|
213
|
-
const signalDeferred =
|
|
224
|
+
const signalDeferred = Promise.withResolvers();
|
|
214
225
|
signalPromise = signalDeferred.promise;
|
|
215
226
|
const sharedListener = () => {
|
|
216
227
|
signalDeferred.reject(signal.reason);
|
|
@@ -260,7 +271,7 @@ function executeOperation(exeContext) {
|
|
|
260
271
|
const { operation, schema, fragments, variableValues, rootValue } = exeContext;
|
|
261
272
|
const rootType = (0, utils_1.getDefinedRootType)(schema, operation.operation, [operation]);
|
|
262
273
|
if (rootType == null) {
|
|
263
|
-
|
|
274
|
+
throw new graphql_1.GraphQLError(`Schema is not configured to execute ${operation.operation} operation.`, {
|
|
264
275
|
nodes: operation,
|
|
265
276
|
});
|
|
266
277
|
}
|
|
@@ -310,7 +321,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields, asyncP
|
|
|
310
321
|
const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath, asyncPayloadRecord);
|
|
311
322
|
if (result !== undefined) {
|
|
312
323
|
results[responseName] = result;
|
|
313
|
-
if ((0,
|
|
324
|
+
if ((0, promise_helpers_1.isPromise)(result)) {
|
|
314
325
|
containsPromise = true;
|
|
315
326
|
}
|
|
316
327
|
}
|
|
@@ -357,20 +368,24 @@ function executeField(exeContext, parentType, source, fieldNodes, path, asyncPay
|
|
|
357
368
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
358
369
|
// variables scope to fulfill any variable references.
|
|
359
370
|
// TODO: find a way to memoize, in case this field is within a List type.
|
|
360
|
-
const args = (0,
|
|
371
|
+
const args = (0, graphql_1.getArgumentValues)(fieldDef, fieldNodes[0],
|
|
372
|
+
// graphql@17 expects VariableValues; graphql@16 expects the flat coerced map.
|
|
373
|
+
(graphql_1.versionInfo.major >= 17
|
|
374
|
+
? exeContext.variableValues
|
|
375
|
+
: exeContext.variableValues.coerced));
|
|
361
376
|
// The resolve function's optional third argument is a context value that
|
|
362
377
|
// is provided to every resolve function within an execution. It is commonly
|
|
363
378
|
// used to represent an authenticated user, or request-specific caches.
|
|
364
379
|
const contextValue = exeContext.contextValue;
|
|
365
380
|
const result = resolveFn(source, args, contextValue, info);
|
|
366
381
|
let completed;
|
|
367
|
-
if ((0,
|
|
382
|
+
if ((0, promise_helpers_1.isPromise)(result)) {
|
|
368
383
|
completed = result.then(resolved => completeValue(exeContext, returnType, fieldNodes, info, path, resolved, asyncPayloadRecord));
|
|
369
384
|
}
|
|
370
385
|
else {
|
|
371
386
|
completed = completeValue(exeContext, returnType, fieldNodes, info, path, result, asyncPayloadRecord);
|
|
372
387
|
}
|
|
373
|
-
if ((0,
|
|
388
|
+
if ((0, promise_helpers_1.isPromise)(completed)) {
|
|
374
389
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
375
390
|
// to take a second callback for the error case.
|
|
376
391
|
return completed.then(undefined, rawError => {
|
|
@@ -443,7 +458,7 @@ function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
|
|
|
443
458
|
return;
|
|
444
459
|
}
|
|
445
460
|
for (const value of maybePromises) {
|
|
446
|
-
if ((0,
|
|
461
|
+
if ((0, promise_helpers_1.isPromise)(value)) {
|
|
447
462
|
waitUntil(value);
|
|
448
463
|
}
|
|
449
464
|
}
|
|
@@ -607,7 +622,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
|
|
|
607
622
|
return completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord);
|
|
608
623
|
}
|
|
609
624
|
if (!(0, utils_1.isIterableObject)(result)) {
|
|
610
|
-
throw
|
|
625
|
+
throw new graphql_1.GraphQLError(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`);
|
|
611
626
|
}
|
|
612
627
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
613
628
|
// This is specified as a simple map, however we're optimizing the path
|
|
@@ -640,13 +655,13 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
|
|
|
640
655
|
function completeListItemValue(item, completedResults, errors, exeContext, itemType, fieldNodes, info, itemPath, asyncPayloadRecord) {
|
|
641
656
|
try {
|
|
642
657
|
let completedItem;
|
|
643
|
-
if ((0,
|
|
658
|
+
if ((0, promise_helpers_1.isPromise)(item)) {
|
|
644
659
|
completedItem = item.then(resolved => completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved, asyncPayloadRecord));
|
|
645
660
|
}
|
|
646
661
|
else {
|
|
647
662
|
completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item, asyncPayloadRecord);
|
|
648
663
|
}
|
|
649
|
-
if ((0,
|
|
664
|
+
if ((0, promise_helpers_1.isPromise)(completedItem)) {
|
|
650
665
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
651
666
|
// to take a second callback for the error case.
|
|
652
667
|
completedResults.push(completedItem.then(undefined, rawError => {
|
|
@@ -702,36 +717,31 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
702
717
|
const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver;
|
|
703
718
|
const contextValue = exeContext.contextValue;
|
|
704
719
|
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
|
|
705
|
-
if ((0,
|
|
720
|
+
if ((0, promise_helpers_1.isPromise)(runtimeType)) {
|
|
706
721
|
return runtimeType.then(resolvedRuntimeType => completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result, asyncPayloadRecord));
|
|
707
722
|
}
|
|
708
723
|
return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result, asyncPayloadRecord);
|
|
709
724
|
}
|
|
710
725
|
function ensureValidRuntimeType(runtimeTypeName, exeContext, returnType, fieldNodes, info, result) {
|
|
711
726
|
if (runtimeTypeName == null) {
|
|
712
|
-
throw
|
|
727
|
+
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}". Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`, { nodes: fieldNodes });
|
|
713
728
|
}
|
|
714
|
-
// releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
|
|
715
|
-
// TODO: remove in 17.0.0 release
|
|
716
729
|
if ((0, graphql_1.isObjectType)(runtimeTypeName)) {
|
|
717
|
-
|
|
718
|
-
throw (0, utils_1.createGraphQLError)('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.');
|
|
719
|
-
}
|
|
720
|
-
runtimeTypeName = runtimeTypeName.name;
|
|
730
|
+
throw new graphql_1.GraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.');
|
|
721
731
|
}
|
|
722
732
|
if (typeof runtimeTypeName !== 'string') {
|
|
723
|
-
throw
|
|
733
|
+
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
|
|
724
734
|
`value ${(0, utils_1.inspect)(result)}, received "${(0, utils_1.inspect)(runtimeTypeName)}".`);
|
|
725
735
|
}
|
|
726
736
|
const runtimeType = exeContext.schema.getType(runtimeTypeName);
|
|
727
737
|
if (runtimeType == null) {
|
|
728
|
-
throw
|
|
738
|
+
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes });
|
|
729
739
|
}
|
|
730
740
|
if (!(0, graphql_1.isObjectType)(runtimeType)) {
|
|
731
|
-
throw
|
|
741
|
+
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes });
|
|
732
742
|
}
|
|
733
743
|
if (!exeContext.schema.isSubType(returnType, runtimeType)) {
|
|
734
|
-
throw
|
|
744
|
+
throw new graphql_1.GraphQLError(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes });
|
|
735
745
|
}
|
|
736
746
|
return runtimeType;
|
|
737
747
|
}
|
|
@@ -744,7 +754,7 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
|
|
|
744
754
|
// than continuing execution.
|
|
745
755
|
if (returnType.isTypeOf) {
|
|
746
756
|
const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
|
|
747
|
-
if ((0,
|
|
757
|
+
if ((0, promise_helpers_1.isPromise)(isTypeOf)) {
|
|
748
758
|
return isTypeOf.then(resolvedIsTypeOf => {
|
|
749
759
|
if (!resolvedIsTypeOf) {
|
|
750
760
|
throw invalidReturnTypeError(returnType, result, fieldNodes);
|
|
@@ -759,7 +769,7 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
|
|
|
759
769
|
return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result, asyncPayloadRecord);
|
|
760
770
|
}
|
|
761
771
|
function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
762
|
-
return
|
|
772
|
+
return new graphql_1.GraphQLError(`Expected value of type "${returnType.name}" but got: ${(0, utils_1.inspect)(result)}.`, {
|
|
763
773
|
nodes: fieldNodes,
|
|
764
774
|
});
|
|
765
775
|
}
|
|
@@ -795,7 +805,7 @@ const defaultTypeResolver = function (value, contextValue, info, abstractType) {
|
|
|
795
805
|
const type = possibleTypes[i];
|
|
796
806
|
if (type.isTypeOf) {
|
|
797
807
|
const isTypeOfResult = type.isTypeOf(value, contextValue, info);
|
|
798
|
-
if ((0,
|
|
808
|
+
if ((0, promise_helpers_1.isPromise)(isTypeOfResult)) {
|
|
799
809
|
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
800
810
|
}
|
|
801
811
|
else if (isTypeOfResult) {
|
|
@@ -882,7 +892,7 @@ function subscribe(args) {
|
|
|
882
892
|
};
|
|
883
893
|
}
|
|
884
894
|
const resultOrStream = createSourceEventStreamImpl(exeContext);
|
|
885
|
-
if ((0,
|
|
895
|
+
if ((0, promise_helpers_1.isPromise)(resultOrStream)) {
|
|
886
896
|
return resultOrStream.then(resolvedResultOrStream => mapSourceToResponse(exeContext, resolvedResultOrStream));
|
|
887
897
|
}
|
|
888
898
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
@@ -900,13 +910,13 @@ function flattenIncrementalResults(incrementalResults) {
|
|
|
900
910
|
},
|
|
901
911
|
next() {
|
|
902
912
|
if (done) {
|
|
903
|
-
return (0,
|
|
913
|
+
return (0, promise_helpers_1.fakePromise)({ value: undefined, done });
|
|
904
914
|
}
|
|
905
915
|
if (initialResultSent) {
|
|
906
916
|
return subsequentIterator.next();
|
|
907
917
|
}
|
|
908
918
|
initialResultSent = true;
|
|
909
|
-
return (0,
|
|
919
|
+
return (0, promise_helpers_1.fakePromise)({
|
|
910
920
|
value: incrementalResults.initialResult,
|
|
911
921
|
done,
|
|
912
922
|
});
|
|
@@ -943,7 +953,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
943
953
|
// the GraphQL specification. The `execute` function provides the
|
|
944
954
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
945
955
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
946
|
-
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0,
|
|
956
|
+
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, promise_helpers_1.mapAsyncIterator)(resultOrStream, (payload) => (0, promise_helpers_1.handleMaybePromise)(() => executeImpl(buildPerEventExecutionContext(exeContext, payload)), ensureAsyncIterable), (error) => {
|
|
947
957
|
if (error instanceof AggregateError) {
|
|
948
958
|
throw new AggregateError(error.errors.map(e => wrapError(e, exeContext.operation)), error.message);
|
|
949
959
|
}
|
|
@@ -951,7 +961,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
951
961
|
}));
|
|
952
962
|
}
|
|
953
963
|
function wrapError(error, operation) {
|
|
954
|
-
return
|
|
964
|
+
return new graphql_1.GraphQLError(error.message, {
|
|
955
965
|
originalError: error,
|
|
956
966
|
nodes: [operation],
|
|
957
967
|
});
|
|
@@ -959,7 +969,7 @@ function wrapError(error, operation) {
|
|
|
959
969
|
function createSourceEventStreamImpl(exeContext) {
|
|
960
970
|
try {
|
|
961
971
|
const eventStream = executeSubscription(exeContext);
|
|
962
|
-
if ((0,
|
|
972
|
+
if ((0, promise_helpers_1.isPromise)(eventStream)) {
|
|
963
973
|
return eventStream.then(undefined, error => ({ errors: [error] }));
|
|
964
974
|
}
|
|
965
975
|
return eventStream;
|
|
@@ -972,7 +982,7 @@ function executeSubscription(exeContext) {
|
|
|
972
982
|
const { schema, fragments, operation, variableValues, rootValue } = exeContext;
|
|
973
983
|
const rootType = schema.getSubscriptionType();
|
|
974
984
|
if (rootType == null) {
|
|
975
|
-
throw
|
|
985
|
+
throw new graphql_1.GraphQLError('Schema is not configured to execute subscription operation.', {
|
|
976
986
|
nodes: operation,
|
|
977
987
|
});
|
|
978
988
|
}
|
|
@@ -981,7 +991,7 @@ function executeSubscription(exeContext) {
|
|
|
981
991
|
const fieldName = fieldNodes[0].name.value;
|
|
982
992
|
const fieldDef = getFieldDef(schema, rootType, fieldNodes[0]);
|
|
983
993
|
if (!fieldDef) {
|
|
984
|
-
throw
|
|
994
|
+
throw new graphql_1.GraphQLError(`The subscription field "${fieldName}" is not defined.`, {
|
|
985
995
|
nodes: fieldNodes,
|
|
986
996
|
});
|
|
987
997
|
}
|
|
@@ -992,7 +1002,7 @@ function executeSubscription(exeContext) {
|
|
|
992
1002
|
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
993
1003
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
994
1004
|
// variables scope to fulfill any variable references.
|
|
995
|
-
const args = (0,
|
|
1005
|
+
const args = (0, graphql_1.getArgumentValues)(fieldDef, fieldNodes[0], (graphql_1.versionInfo.major >= 17 ? variableValues : variableValues.coerced));
|
|
996
1006
|
// The resolve function's optional third argument is a context value that
|
|
997
1007
|
// is provided to every resolve function within an execution. It is commonly
|
|
998
1008
|
// used to represent an authenticated user, or request-specific caches.
|
|
@@ -1001,7 +1011,7 @@ function executeSubscription(exeContext) {
|
|
|
1001
1011
|
// AsyncIterable yielding raw payloads.
|
|
1002
1012
|
const resolveFn = fieldDef.subscribe ?? exeContext.subscribeFieldResolver;
|
|
1003
1013
|
const result = resolveFn(rootValue, args, contextValue, info);
|
|
1004
|
-
if ((0,
|
|
1014
|
+
if ((0, promise_helpers_1.isPromise)(result)) {
|
|
1005
1015
|
return result
|
|
1006
1016
|
.then(result => assertEventStream(result, exeContext.signal, exeContext.onSignalAbort))
|
|
1007
1017
|
.then(undefined, error => {
|
|
@@ -1021,7 +1031,7 @@ function assertEventStream(result, signal, onSignalAbort) {
|
|
|
1021
1031
|
}
|
|
1022
1032
|
// Assert field returned an event stream, otherwise yield an error.
|
|
1023
1033
|
if (!(0, utils_1.isAsyncIterable)(result)) {
|
|
1024
|
-
throw
|
|
1034
|
+
throw new graphql_1.GraphQLError('Subscription field must return Async Iterable. ' + `Received: ${(0, utils_1.inspect)(result)}.`);
|
|
1025
1035
|
}
|
|
1026
1036
|
if (onSignalAbort) {
|
|
1027
1037
|
return {
|
|
@@ -1048,7 +1058,7 @@ function executeDeferredFragment(exeContext, parentType, sourceValue, fields, la
|
|
|
1048
1058
|
let promiseOrData;
|
|
1049
1059
|
try {
|
|
1050
1060
|
promiseOrData = executeFields(exeContext, parentType, sourceValue, path, fields, asyncPayloadRecord);
|
|
1051
|
-
if ((0,
|
|
1061
|
+
if ((0, promise_helpers_1.isPromise)(promiseOrData)) {
|
|
1052
1062
|
promiseOrData = promiseOrData.then(null, e => {
|
|
1053
1063
|
asyncPayloadRecord.errors.push(e);
|
|
1054
1064
|
return null;
|
|
@@ -1071,13 +1081,13 @@ function executeStreamField(path, itemPath, item, exeContext, fieldNodes, info,
|
|
|
1071
1081
|
let completedItem;
|
|
1072
1082
|
try {
|
|
1073
1083
|
try {
|
|
1074
|
-
if ((0,
|
|
1084
|
+
if ((0, promise_helpers_1.isPromise)(item)) {
|
|
1075
1085
|
completedItem = item.then(resolved => completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved, asyncPayloadRecord));
|
|
1076
1086
|
}
|
|
1077
1087
|
else {
|
|
1078
1088
|
completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item, asyncPayloadRecord);
|
|
1079
1089
|
}
|
|
1080
|
-
if ((0,
|
|
1090
|
+
if ((0, promise_helpers_1.isPromise)(completedItem)) {
|
|
1081
1091
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
1082
1092
|
// to take a second callback for the error case.
|
|
1083
1093
|
completedItem = completedItem.then(undefined, rawError => {
|
|
@@ -1103,7 +1113,7 @@ function executeStreamField(path, itemPath, item, exeContext, fieldNodes, info,
|
|
|
1103
1113
|
return asyncPayloadRecord;
|
|
1104
1114
|
}
|
|
1105
1115
|
let completedItems;
|
|
1106
|
-
if ((0,
|
|
1116
|
+
if ((0, promise_helpers_1.isPromise)(completedItem)) {
|
|
1107
1117
|
completedItems = completedItem.then(value => [value], error => {
|
|
1108
1118
|
asyncPayloadRecord.errors.push(error);
|
|
1109
1119
|
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
|
|
@@ -1136,7 +1146,7 @@ async function executeStreamIteratorItem(iterator, exeContext, fieldNodes, info,
|
|
|
1136
1146
|
let completedItem;
|
|
1137
1147
|
try {
|
|
1138
1148
|
completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item, asyncPayloadRecord);
|
|
1139
|
-
if ((0,
|
|
1149
|
+
if ((0, promise_helpers_1.isPromise)(completedItem)) {
|
|
1140
1150
|
completedItem = completedItem.then(undefined, rawError => {
|
|
1141
1151
|
const error = (0, utils_1.locatedError)(rawError, fieldNodes, (0, utils_1.pathToArray)(itemPath), exeContext.schemaCoordinateInErrors && info);
|
|
1142
1152
|
const handledError = handleFieldError(error, itemType, asyncPayloadRecord.errors);
|
|
@@ -1183,7 +1193,7 @@ async function executeStreamIterator(initialIndex, iterator, exeContext, fieldNo
|
|
|
1183
1193
|
}
|
|
1184
1194
|
const { done, value: completedItem } = iteration;
|
|
1185
1195
|
let completedItems;
|
|
1186
|
-
if ((0,
|
|
1196
|
+
if ((0, promise_helpers_1.isPromise)(completedItem)) {
|
|
1187
1197
|
completedItems = completedItem.then(value => [value], error => {
|
|
1188
1198
|
asyncPayloadRecord.errors.push(error);
|
|
1189
1199
|
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executorFromSchema = void 0;
|
|
4
4
|
exports.normalizedExecutor = normalizedExecutor;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
5
6
|
const graphql_1 = require("graphql");
|
|
6
|
-
const
|
|
7
|
+
const weak_js_1 = tslib_1.__importDefault(require("memoizee/weak.js"));
|
|
7
8
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
8
9
|
const execute_js_1 = require("./execute.js");
|
|
9
10
|
function normalizedExecutor(args) {
|
|
@@ -21,7 +22,7 @@ function normalizedExecutor(args) {
|
|
|
21
22
|
return result;
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
exports.executorFromSchema = (0,
|
|
25
|
+
exports.executorFromSchema = (0, weak_js_1.default)(function executorFromSchema(schema) {
|
|
25
26
|
return function schemaExecutor(request) {
|
|
26
27
|
return normalizedExecutor({
|
|
27
28
|
schema,
|
|
@@ -163,7 +163,7 @@ function validateInputValueImpl(inputValue, type, onError, hideSuggestions, path
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
function reportInvalidValue(onError, message, path, invalidValue, originalError) {
|
|
166
|
-
onError((0, utils_1.pathToArray)(path), invalidValue,
|
|
166
|
+
onError((0, utils_1.pathToArray)(path), invalidValue, new graphql_1.GraphQLError(message, { originalError }));
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* Validate that the provided input literal is allowed for this type, collecting
|
|
@@ -387,7 +387,7 @@ function getScopedVariableValues(context, valueNode) {
|
|
|
387
387
|
return fragmentVariableValues?.sources?.[variableName] ? fragmentVariableValues : variables;
|
|
388
388
|
}
|
|
389
389
|
function reportInvalidLiteral(onError, message, valueNode, path, originalError) {
|
|
390
|
-
onError(
|
|
390
|
+
onError(new graphql_1.GraphQLError(message, {
|
|
391
391
|
nodes: valueNode,
|
|
392
392
|
originalError,
|
|
393
393
|
}), (0, utils_1.pathToArray)(path));
|
package/cjs/execution/values.js
CHANGED
|
@@ -19,7 +19,7 @@ function getVariableValues(schema, varDefNodes, inputs, options) {
|
|
|
19
19
|
try {
|
|
20
20
|
const variableValues = coerceVariableValues(schema, varDefNodes, inputs, error => {
|
|
21
21
|
if (maxErrors != null && errors.length >= maxErrors) {
|
|
22
|
-
throw
|
|
22
|
+
throw new graphql_1.GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
|
|
23
23
|
}
|
|
24
24
|
errors.push(error);
|
|
25
25
|
});
|
|
@@ -42,7 +42,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
42
42
|
// Must use input types for variables. This should be caught during
|
|
43
43
|
// validation, however is checked again here for safety.
|
|
44
44
|
const varTypeStr = (0, graphql_1.print)(varDefNode.type);
|
|
45
|
-
onError(
|
|
45
|
+
onError(new graphql_1.GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type }));
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
48
|
const signature = {
|
|
@@ -57,7 +57,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
57
57
|
}
|
|
58
58
|
else if ((0, graphql_1.isNonNullType)(varType)) {
|
|
59
59
|
const varTypeStr = (0, utils_1.inspect)(varType);
|
|
60
|
-
onError(
|
|
60
|
+
onError(new graphql_1.GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, {
|
|
61
61
|
nodes: varDefNode,
|
|
62
62
|
}));
|
|
63
63
|
}
|
|
@@ -68,7 +68,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
68
68
|
sources[varName] = { signature, value: sourceValue };
|
|
69
69
|
if (value === null && (0, graphql_1.isNonNullType)(varType)) {
|
|
70
70
|
const varTypeStr = (0, utils_1.inspect)(varType);
|
|
71
|
-
onError(
|
|
71
|
+
onError(new graphql_1.GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, {
|
|
72
72
|
nodes: varDefNode,
|
|
73
73
|
}));
|
|
74
74
|
continue;
|
|
@@ -80,7 +80,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
80
80
|
if (path.length > 0) {
|
|
81
81
|
prefix += ` at "${varName}${(0, utils_1.printPathArray)(path)}"`;
|
|
82
82
|
}
|
|
83
|
-
onError(
|
|
83
|
+
onError(new graphql_1.GraphQLError(prefix + '; ' + error.message, {
|
|
84
84
|
nodes: varDefNode,
|
|
85
85
|
originalError: error,
|
|
86
86
|
}));
|
package/esm/execution/execute.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { assertValidSchema, GraphQLError, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, Kind, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, versionInfo, } from 'graphql';
|
|
2
|
-
import
|
|
1
|
+
import { assertValidSchema, getArgumentValues, GraphQLError, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, Kind, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, versionInfo, } from 'graphql';
|
|
2
|
+
import weakMemoizee from 'memoizee/weak.js';
|
|
3
|
+
import { collectSubFields as _collectSubfields, addPath, collectFields, getDefinedRootType, getDirectiveValues, GraphQLStreamDirective, inspect, isAsyncIterable, isIterableObject, isObjectLike, locatedError, pathToArray, promiseReduce, } from '@graphql-tools/utils';
|
|
3
4
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
|
-
import {
|
|
5
|
+
import { fakePromise, handleMaybePromise, isPromise, mapAsyncIterator, } from '@whatwg-node/promise-helpers';
|
|
5
6
|
import { coerceError } from './coerceError.js';
|
|
6
7
|
import { flattenAsyncIterable } from './flattenAsyncIterable.js';
|
|
7
8
|
import { invariant } from './invariant.js';
|
|
@@ -12,7 +13,16 @@ import { getVariableValues } from './values.js';
|
|
|
12
13
|
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
13
14
|
* saves overhead when resolving lists of values.
|
|
14
15
|
*/
|
|
15
|
-
const
|
|
16
|
+
const collectSubfieldsMemo = weakMemoizee(function collectSubfieldsExeContext(exeContext) {
|
|
17
|
+
return weakMemoizee(function collectSubfieldsReturnType(returnType) {
|
|
18
|
+
return weakMemoizee(function collectSubfieldsFieldNodes(fieldNodes) {
|
|
19
|
+
return _collectSubfields(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
function collectSubfields(exeContext, returnType, fieldNodes) {
|
|
24
|
+
return collectSubfieldsMemo(exeContext)(returnType)(fieldNodes);
|
|
25
|
+
}
|
|
16
26
|
/**
|
|
17
27
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
18
28
|
* including `@defer` and `@stream` as proposed in
|
|
@@ -117,7 +127,7 @@ export function assertValidExecutionArguments(schema, document, rawVariableValue
|
|
|
117
127
|
// Variables, if provided, must be an object.
|
|
118
128
|
console.assert(rawVariableValues == null || isObjectLike(rawVariableValues), 'Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided.');
|
|
119
129
|
}
|
|
120
|
-
export const getFragmentsFromDocument =
|
|
130
|
+
export const getFragmentsFromDocument = weakMemoizee(function getFragmentsFromDocument(document) {
|
|
121
131
|
const fragments = Object.create(null);
|
|
122
132
|
for (const definition of document.definitions) {
|
|
123
133
|
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
|
|
@@ -148,7 +158,7 @@ export function buildExecutionContext(args) {
|
|
|
148
158
|
if (operationName == null) {
|
|
149
159
|
if (operation !== undefined) {
|
|
150
160
|
return [
|
|
151
|
-
|
|
161
|
+
new GraphQLError('Must provide operation name if query contains multiple operations.', {
|
|
152
162
|
extensions: {
|
|
153
163
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
154
164
|
},
|
|
@@ -168,7 +178,7 @@ export function buildExecutionContext(args) {
|
|
|
168
178
|
if (operation == null) {
|
|
169
179
|
if (operationName != null) {
|
|
170
180
|
return [
|
|
171
|
-
|
|
181
|
+
new GraphQLError(`Unknown operation named "${operationName}".`, {
|
|
172
182
|
extensions: {
|
|
173
183
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
174
184
|
},
|
|
@@ -176,7 +186,7 @@ export function buildExecutionContext(args) {
|
|
|
176
186
|
];
|
|
177
187
|
}
|
|
178
188
|
return [
|
|
179
|
-
|
|
189
|
+
new GraphQLError('Must provide an operation.', {
|
|
180
190
|
extensions: {
|
|
181
191
|
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
182
192
|
},
|
|
@@ -197,7 +207,7 @@ export function buildExecutionContext(args) {
|
|
|
197
207
|
let signalPromise;
|
|
198
208
|
if (signal) {
|
|
199
209
|
const listeners = new Set();
|
|
200
|
-
const signalDeferred =
|
|
210
|
+
const signalDeferred = Promise.withResolvers();
|
|
201
211
|
signalPromise = signalDeferred.promise;
|
|
202
212
|
const sharedListener = () => {
|
|
203
213
|
signalDeferred.reject(signal.reason);
|
|
@@ -247,7 +257,7 @@ function executeOperation(exeContext) {
|
|
|
247
257
|
const { operation, schema, fragments, variableValues, rootValue } = exeContext;
|
|
248
258
|
const rootType = getDefinedRootType(schema, operation.operation, [operation]);
|
|
249
259
|
if (rootType == null) {
|
|
250
|
-
|
|
260
|
+
throw new GraphQLError(`Schema is not configured to execute ${operation.operation} operation.`, {
|
|
251
261
|
nodes: operation,
|
|
252
262
|
});
|
|
253
263
|
}
|
|
@@ -344,7 +354,11 @@ function executeField(exeContext, parentType, source, fieldNodes, path, asyncPay
|
|
|
344
354
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
345
355
|
// variables scope to fulfill any variable references.
|
|
346
356
|
// TODO: find a way to memoize, in case this field is within a List type.
|
|
347
|
-
const args = getArgumentValues(fieldDef, fieldNodes[0],
|
|
357
|
+
const args = getArgumentValues(fieldDef, fieldNodes[0],
|
|
358
|
+
// graphql@17 expects VariableValues; graphql@16 expects the flat coerced map.
|
|
359
|
+
(versionInfo.major >= 17
|
|
360
|
+
? exeContext.variableValues
|
|
361
|
+
: exeContext.variableValues.coerced));
|
|
348
362
|
// The resolve function's optional third argument is a context value that
|
|
349
363
|
// is provided to every resolve function within an execution. It is commonly
|
|
350
364
|
// used to represent an authenticated user, or request-specific caches.
|
|
@@ -594,7 +608,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
|
|
|
594
608
|
return completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator, asyncPayloadRecord);
|
|
595
609
|
}
|
|
596
610
|
if (!isIterableObject(result)) {
|
|
597
|
-
throw
|
|
611
|
+
throw new GraphQLError(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`);
|
|
598
612
|
}
|
|
599
613
|
const stream = getStreamValues(exeContext, fieldNodes, path);
|
|
600
614
|
// This is specified as a simple map, however we're optimizing the path
|
|
@@ -696,29 +710,24 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
696
710
|
}
|
|
697
711
|
function ensureValidRuntimeType(runtimeTypeName, exeContext, returnType, fieldNodes, info, result) {
|
|
698
712
|
if (runtimeTypeName == null) {
|
|
699
|
-
throw
|
|
713
|
+
throw new GraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}". Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`, { nodes: fieldNodes });
|
|
700
714
|
}
|
|
701
|
-
// releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
|
|
702
|
-
// TODO: remove in 17.0.0 release
|
|
703
715
|
if (isObjectType(runtimeTypeName)) {
|
|
704
|
-
|
|
705
|
-
throw createGraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.');
|
|
706
|
-
}
|
|
707
|
-
runtimeTypeName = runtimeTypeName.name;
|
|
716
|
+
throw new GraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.');
|
|
708
717
|
}
|
|
709
718
|
if (typeof runtimeTypeName !== 'string') {
|
|
710
|
-
throw
|
|
719
|
+
throw new GraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
|
|
711
720
|
`value ${inspect(result)}, received "${inspect(runtimeTypeName)}".`);
|
|
712
721
|
}
|
|
713
722
|
const runtimeType = exeContext.schema.getType(runtimeTypeName);
|
|
714
723
|
if (runtimeType == null) {
|
|
715
|
-
throw
|
|
724
|
+
throw new GraphQLError(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes });
|
|
716
725
|
}
|
|
717
726
|
if (!isObjectType(runtimeType)) {
|
|
718
|
-
throw
|
|
727
|
+
throw new GraphQLError(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes });
|
|
719
728
|
}
|
|
720
729
|
if (!exeContext.schema.isSubType(returnType, runtimeType)) {
|
|
721
|
-
throw
|
|
730
|
+
throw new GraphQLError(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes });
|
|
722
731
|
}
|
|
723
732
|
return runtimeType;
|
|
724
733
|
}
|
|
@@ -746,7 +755,7 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
|
|
|
746
755
|
return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result, asyncPayloadRecord);
|
|
747
756
|
}
|
|
748
757
|
function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
749
|
-
return
|
|
758
|
+
return new GraphQLError(`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`, {
|
|
750
759
|
nodes: fieldNodes,
|
|
751
760
|
});
|
|
752
761
|
}
|
|
@@ -936,7 +945,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
936
945
|
}));
|
|
937
946
|
}
|
|
938
947
|
function wrapError(error, operation) {
|
|
939
|
-
return
|
|
948
|
+
return new GraphQLError(error.message, {
|
|
940
949
|
originalError: error,
|
|
941
950
|
nodes: [operation],
|
|
942
951
|
});
|
|
@@ -957,7 +966,7 @@ function executeSubscription(exeContext) {
|
|
|
957
966
|
const { schema, fragments, operation, variableValues, rootValue } = exeContext;
|
|
958
967
|
const rootType = schema.getSubscriptionType();
|
|
959
968
|
if (rootType == null) {
|
|
960
|
-
throw
|
|
969
|
+
throw new GraphQLError('Schema is not configured to execute subscription operation.', {
|
|
961
970
|
nodes: operation,
|
|
962
971
|
});
|
|
963
972
|
}
|
|
@@ -966,7 +975,7 @@ function executeSubscription(exeContext) {
|
|
|
966
975
|
const fieldName = fieldNodes[0].name.value;
|
|
967
976
|
const fieldDef = getFieldDef(schema, rootType, fieldNodes[0]);
|
|
968
977
|
if (!fieldDef) {
|
|
969
|
-
throw
|
|
978
|
+
throw new GraphQLError(`The subscription field "${fieldName}" is not defined.`, {
|
|
970
979
|
nodes: fieldNodes,
|
|
971
980
|
});
|
|
972
981
|
}
|
|
@@ -977,7 +986,7 @@ function executeSubscription(exeContext) {
|
|
|
977
986
|
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
978
987
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
979
988
|
// variables scope to fulfill any variable references.
|
|
980
|
-
const args = getArgumentValues(fieldDef, fieldNodes[0],
|
|
989
|
+
const args = getArgumentValues(fieldDef, fieldNodes[0], (versionInfo.major >= 17 ? variableValues : variableValues.coerced));
|
|
981
990
|
// The resolve function's optional third argument is a context value that
|
|
982
991
|
// is provided to every resolve function within an execution. It is commonly
|
|
983
992
|
// used to represent an authenticated user, or request-specific caches.
|
|
@@ -1006,7 +1015,7 @@ function assertEventStream(result, signal, onSignalAbort) {
|
|
|
1006
1015
|
}
|
|
1007
1016
|
// Assert field returned an event stream, otherwise yield an error.
|
|
1008
1017
|
if (!isAsyncIterable(result)) {
|
|
1009
|
-
throw
|
|
1018
|
+
throw new GraphQLError('Subscription field must return Async Iterable. ' + `Received: ${inspect(result)}.`);
|
|
1010
1019
|
}
|
|
1011
1020
|
if (onSignalAbort) {
|
|
1012
1021
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getOperationAST } from 'graphql';
|
|
2
|
-
import
|
|
2
|
+
import weakMemoizee from 'memoizee/weak.js';
|
|
3
3
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
4
|
import { execute, flattenIncrementalResults, isIncrementalResults, subscribe, } from './execute.js';
|
|
5
5
|
export function normalizedExecutor(args) {
|
|
@@ -17,7 +17,7 @@ export function normalizedExecutor(args) {
|
|
|
17
17
|
return result;
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
export const executorFromSchema =
|
|
20
|
+
export const executorFromSchema = weakMemoizee(function executorFromSchema(schema) {
|
|
21
21
|
return function schemaExecutor(request) {
|
|
22
22
|
return normalizedExecutor({
|
|
23
23
|
schema,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertLeafType, GraphQLError, isInputObjectType, isListType, isNonNullType, isRequiredInputField, Kind, print, versionInfo, } from 'graphql';
|
|
2
|
-
import { addPath,
|
|
2
|
+
import { addPath, inspect, isIterableObject, isObjectLike, pathToArray, } from '@graphql-tools/utils';
|
|
3
3
|
import { didYouMean } from './didYouMean.js';
|
|
4
4
|
import { suggestionList } from './suggestionList.js';
|
|
5
5
|
/**
|
|
@@ -158,7 +158,7 @@ function validateInputValueImpl(inputValue, type, onError, hideSuggestions, path
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
function reportInvalidValue(onError, message, path, invalidValue, originalError) {
|
|
161
|
-
onError(pathToArray(path), invalidValue,
|
|
161
|
+
onError(pathToArray(path), invalidValue, new GraphQLError(message, { originalError }));
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Validate that the provided input literal is allowed for this type, collecting
|
|
@@ -382,7 +382,7 @@ function getScopedVariableValues(context, valueNode) {
|
|
|
382
382
|
return fragmentVariableValues?.sources?.[variableName] ? fragmentVariableValues : variables;
|
|
383
383
|
}
|
|
384
384
|
function reportInvalidLiteral(onError, message, valueNode, path, originalError) {
|
|
385
|
-
onError(
|
|
385
|
+
onError(new GraphQLError(message, {
|
|
386
386
|
nodes: valueNode,
|
|
387
387
|
originalError,
|
|
388
388
|
}), pathToArray(path));
|
package/esm/execution/values.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { coerceInputValue, isInputObjectType, isInputType, isListType, isNonNullType, print, typeFromAST, valueFromAST, } from 'graphql';
|
|
2
|
-
import {
|
|
1
|
+
import { coerceInputValue, GraphQLError, isInputObjectType, isInputType, isListType, isNonNullType, print, typeFromAST, valueFromAST, } from 'graphql';
|
|
2
|
+
import { hasOwnProperty, inspect, printPathArray, } from '@graphql-tools/utils';
|
|
3
3
|
import { validateInputValue } from './validateInputValue.js';
|
|
4
4
|
/**
|
|
5
5
|
* Prepares an object map of variableValues of the correct type based on the
|
|
@@ -16,7 +16,7 @@ export function getVariableValues(schema, varDefNodes, inputs, options) {
|
|
|
16
16
|
try {
|
|
17
17
|
const variableValues = coerceVariableValues(schema, varDefNodes, inputs, error => {
|
|
18
18
|
if (maxErrors != null && errors.length >= maxErrors) {
|
|
19
|
-
throw
|
|
19
|
+
throw new GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
|
|
20
20
|
}
|
|
21
21
|
errors.push(error);
|
|
22
22
|
});
|
|
@@ -39,7 +39,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
39
39
|
// Must use input types for variables. This should be caught during
|
|
40
40
|
// validation, however is checked again here for safety.
|
|
41
41
|
const varTypeStr = print(varDefNode.type);
|
|
42
|
-
onError(
|
|
42
|
+
onError(new GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type }));
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
const signature = {
|
|
@@ -54,7 +54,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
54
54
|
}
|
|
55
55
|
else if (isNonNullType(varType)) {
|
|
56
56
|
const varTypeStr = inspect(varType);
|
|
57
|
-
onError(
|
|
57
|
+
onError(new GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, {
|
|
58
58
|
nodes: varDefNode,
|
|
59
59
|
}));
|
|
60
60
|
}
|
|
@@ -65,7 +65,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
65
65
|
sources[varName] = { signature, value: sourceValue };
|
|
66
66
|
if (value === null && isNonNullType(varType)) {
|
|
67
67
|
const varTypeStr = inspect(varType);
|
|
68
|
-
onError(
|
|
68
|
+
onError(new GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, {
|
|
69
69
|
nodes: varDefNode,
|
|
70
70
|
}));
|
|
71
71
|
continue;
|
|
@@ -77,7 +77,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
|
77
77
|
if (path.length > 0) {
|
|
78
78
|
prefix += ` at "${varName}${printPathArray(path)}"`;
|
|
79
79
|
}
|
|
80
|
-
onError(
|
|
80
|
+
onError(new GraphQLError(prefix + '; ' + error.message, {
|
|
81
81
|
nodes: varDefNode,
|
|
82
82
|
originalError: error,
|
|
83
83
|
}));
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/executor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha-20261015151226-5868300779ac4a46f260b4a5fd3fd669c4d7cba8",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"graphql": "^
|
|
6
|
+
"graphql": "^16.0.0 || ^17.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-tools/utils": "
|
|
9
|
+
"@graphql-tools/utils": "13.0.0-alpha-20261015151226-5868300779ac4a46f260b4a5fd3fd669c4d7cba8",
|
|
10
10
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
11
11
|
"@repeaterjs/repeater": "^3.1.0",
|
|
12
12
|
"@whatwg-node/disposablestack": "^0.1.0",
|
|
13
13
|
"@whatwg-node/promise-helpers": "^2.0.0",
|
|
14
|
+
"memoizee": "^0.4.17",
|
|
14
15
|
"tslib": "^2.4.0"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"author": "Saihajpreet Singh <saihajpreet.singh@gmail.com>",
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
30
|
+
"node": ">=22.14.0"
|
|
30
31
|
},
|
|
31
32
|
"main": "cjs/index.js",
|
|
32
33
|
"module": "esm/index.js",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GraphQLResolveInfo, Maybe,
|
|
1
|
+
import { FieldNode, FragmentDefinitionNode, GraphQLError, GraphQLField, GraphQLFieldResolver, GraphQLFormattedError, GraphQLObjectType, GraphQLSchema, GraphQLTypeResolver, OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import { GraphQLResolveInfo, Maybe, Path, VariableValues } from '@graphql-tools/utils';
|
|
3
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
|
+
import { type MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
5
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
5
6
|
errors?: ReadonlyArray<GraphQLError>;
|
|
6
7
|
data?: TData | null;
|
|
@@ -140,7 +141,7 @@ export declare function executeSync(args: ExecutionArgs): SingularExecutionResul
|
|
|
140
141
|
* @internal
|
|
141
142
|
*/
|
|
142
143
|
export declare function assertValidExecutionArguments<TVariables>(schema: GraphQLSchema, document: TypedDocumentNode<any, TVariables>, rawVariableValues: Maybe<TVariables>): void;
|
|
143
|
-
export declare const getFragmentsFromDocument:
|
|
144
|
+
export declare const getFragmentsFromDocument: any;
|
|
144
145
|
/**
|
|
145
146
|
* Constructs a ExecutionContext object from the arguments passed to
|
|
146
147
|
* execute, which we will pass throughout the other execution methods.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GraphQLResolveInfo, Maybe,
|
|
1
|
+
import { FieldNode, FragmentDefinitionNode, GraphQLError, GraphQLField, GraphQLFieldResolver, GraphQLFormattedError, GraphQLObjectType, GraphQLSchema, GraphQLTypeResolver, OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import { GraphQLResolveInfo, Maybe, Path, VariableValues } from '@graphql-tools/utils';
|
|
3
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
|
+
import { type MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
5
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
5
6
|
errors?: ReadonlyArray<GraphQLError>;
|
|
6
7
|
data?: TData | null;
|
|
@@ -140,7 +141,7 @@ export declare function executeSync(args: ExecutionArgs): SingularExecutionResul
|
|
|
140
141
|
* @internal
|
|
141
142
|
*/
|
|
142
143
|
export declare function assertValidExecutionArguments<TVariables>(schema: GraphQLSchema, document: TypedDocumentNode<any, TVariables>, rawVariableValues: Maybe<TVariables>): void;
|
|
143
|
-
export declare const getFragmentsFromDocument:
|
|
144
|
+
export declare const getFragmentsFromDocument: any;
|
|
144
145
|
/**
|
|
145
146
|
* Constructs a ExecutionContext object from the arguments passed to
|
|
146
147
|
* execute, which we will pass throughout the other execution methods.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExecutionResult, MaybeAsyncIterable } from '@graphql-tools/utils';
|
|
2
|
+
import { type MaybePromise } from '@whatwg-node/promise-helpers';
|
|
3
3
|
import { ExecutionArgs } from './execute.cjs';
|
|
4
4
|
export declare function normalizedExecutor<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>;
|
|
5
|
-
export declare const executorFromSchema:
|
|
5
|
+
export declare const executorFromSchema: any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExecutionResult, MaybeAsyncIterable } from '@graphql-tools/utils';
|
|
2
|
+
import { type MaybePromise } from '@whatwg-node/promise-helpers';
|
|
3
3
|
import { ExecutionArgs } from './execute.js';
|
|
4
4
|
export declare function normalizedExecutor<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>;
|
|
5
|
-
export declare const executorFromSchema:
|
|
5
|
+
export declare const executorFromSchema: any;
|