@graphql-tools/executor
Advanced tools
Comparing version 0.0.1-alpha-20221025014654-e3be5659 to 0.0.1-alpha-20221025154355-1d847f5a
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFieldDef = exports.createSourceEventStream = exports.subscribe = exports.defaultFieldResolver = exports.defaultTypeResolver = exports.buildResolveInfo = exports.buildExecutionContext = exports.assertValidExecutionArguments = exports.executeSync = exports.execute = void 0; | ||
const devAssert_js_1 = require("graphql/jsutils/devAssert.js"); | ||
const inspect_js_1 = require("graphql/jsutils/inspect.js"); | ||
const invariant_js_1 = require("graphql/jsutils/invariant.js"); | ||
const isAsyncIterable_js_1 = require("graphql/jsutils/isAsyncIterable.js"); | ||
const isIterableObject_js_1 = require("graphql/jsutils/isIterableObject.js"); | ||
const isObjectLike_js_1 = require("graphql/jsutils/isObjectLike.js"); | ||
const isPromise_js_1 = require("graphql/jsutils/isPromise.js"); | ||
const memoize3_js_1 = require("graphql/jsutils/memoize3.js"); | ||
const Path_js_1 = require("graphql/jsutils/Path.js"); | ||
const promiseForObject_js_1 = require("graphql/jsutils/promiseForObject.js"); | ||
const promiseReduce_js_1 = require("graphql/jsutils/promiseReduce.js"); | ||
const graphql_1 = require("graphql"); | ||
const collectFields_js_1 = require("./collectFields.js"); | ||
const mapAsyncIterator_js_1 = require("./mapAsyncIterator.js"); | ||
const values_js_1 = require("./values.js"); | ||
// This file contains a lot of such errors but we plan to refactor it anyway | ||
// so just disable it for entire file. | ||
const utils_1 = require("@graphql-tools/utils"); | ||
/** | ||
* A memoized collection of relevant subfields with regard to the return | ||
* type. Memoizing ensures the subfields are not repeatedly calculated, which | ||
* saves overhead when resolving lists of values. | ||
*/ | ||
const collectSubfields = (0, memoize3_js_1.memoize3)((exeContext, returnType, fieldNodes) => (0, collectFields_js_1.collectSubfields)(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes)); | ||
/** | ||
* Implements the "Executing requests" section of the GraphQL specification. | ||
@@ -62,3 +43,3 @@ * | ||
const result = executeOperation(exeContext); | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
return result.then(data => buildResponse(data, exeContext.errors), error => { | ||
@@ -84,3 +65,3 @@ exeContext.errors.push(error); | ||
// Assert that the execution was synchronous. | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
throw new Error('GraphQL execution failed to complete synchronously.'); | ||
@@ -105,7 +86,7 @@ } | ||
function assertValidExecutionArguments(schema, document, rawVariableValues) { | ||
(0, devAssert_js_1.devAssert)(!!document, 'Must provide document.'); | ||
console.assert(!!document, 'Must provide document.'); | ||
// If the schema used for execution is invalid, throw an error. | ||
(0, graphql_1.assertValidSchema)(schema); | ||
// Variables, if provided, must be an object. | ||
(0, devAssert_js_1.devAssert)(rawVariableValues == null || (0, isObjectLike_js_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.'); | ||
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.'); | ||
} | ||
@@ -134,3 +115,3 @@ exports.assertValidExecutionArguments = assertValidExecutionArguments; | ||
if (operation !== undefined) { | ||
return [new graphql_1.GraphQLError('Must provide operation name if query contains multiple operations.')]; | ||
return [(0, utils_1.createGraphQLError)('Must provide operation name if query contains multiple operations.')]; | ||
} | ||
@@ -152,5 +133,5 @@ operation = definition; | ||
if (operationName != null) { | ||
return [new graphql_1.GraphQLError(`Unknown operation named "${operationName}".`)]; | ||
return [(0, utils_1.createGraphQLError)(`Unknown operation named "${operationName}".`)]; | ||
} | ||
return [new graphql_1.GraphQLError('Must provide an operation.')]; | ||
return [(0, utils_1.createGraphQLError)('Must provide an operation.')]; | ||
} | ||
@@ -194,7 +175,7 @@ // FIXME: https://github.com/graphql/graphql-js/issues/2203 | ||
if (rootType == null) { | ||
throw new graphql_1.GraphQLError(`Schema is not configured to execute ${operation.operation} operation.`, { | ||
throw (0, utils_1.createGraphQLError)(`Schema is not configured to execute ${operation.operation} operation.`, { | ||
nodes: operation, | ||
}); | ||
} | ||
const rootFields = (0, collectFields_js_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const rootFields = (0, utils_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const path = undefined; | ||
@@ -217,3 +198,3 @@ switch (operation.operation) { | ||
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) { | ||
return (0, promiseReduce_js_1.promiseReduce)(fields.entries(), (results, [responseName, fieldNodes]) => { | ||
return promiseReduce(fields.entries(), (results, [responseName, fieldNodes]) => { | ||
const fieldPath = (0, Path_js_1.addPath)(path, responseName, parentType.name); | ||
@@ -224,3 +205,3 @@ const result = executeField(exeContext, parentType, sourceValue, fieldNodes, fieldPath); | ||
} | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
return result.then(resolvedResult => { | ||
@@ -247,3 +228,3 @@ results[responseName] = resolvedResult; | ||
results[responseName] = result; | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
containsPromise = true; | ||
@@ -260,3 +241,9 @@ } | ||
// same map, but with any promises replaced with the values they resolved to. | ||
return (0, promiseForObject_js_1.promiseForObject)(results); | ||
return Promise.all(Object.values(results)).then(resolvedValues => { | ||
const resolvedObject = Object.create(null); | ||
for (const [i, key] of Object.keys(results).entries()) { | ||
resolvedObject[key] = resolvedValues[i]; | ||
} | ||
return resolvedObject; | ||
}); | ||
} | ||
@@ -290,3 +277,3 @@ /** | ||
let completed; | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
completed = result.then(resolved => completeValue(exeContext, returnType, fieldNodes, info, path, resolved)); | ||
@@ -297,3 +284,3 @@ } | ||
} | ||
if ((0, isPromise_js_1.isPromise)(completed)) { | ||
if (isPromise(completed)) { | ||
// Note: we don't rely on a `catch` method, but we do expect "thenable" | ||
@@ -404,3 +391,3 @@ // to take a second callback for the error case. | ||
// Not reachable, all possible output types have been considered. | ||
(0, invariant_js_1.invariant)(false, 'Cannot complete value of unexpected output type: ' + (0, inspect_js_1.inspect)(returnType)); | ||
console.assert(false, 'Cannot complete value of unexpected output type: ' + (0, utils_1.inspect)(returnType)); | ||
} | ||
@@ -425,3 +412,3 @@ /** | ||
const completedItem = completeValue(exeContext, itemType, fieldNodes, info, fieldPath, value); | ||
if ((0, isPromise_js_1.isPromise)(completedItem)) { | ||
if (isPromise(completedItem)) { | ||
containsPromise = true; | ||
@@ -447,2 +434,20 @@ } | ||
} | ||
function isIterableObject(value) { | ||
return value != null && typeof value === 'object' && Symbol.iterator in value; | ||
} | ||
function isObjectLike(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
function isPromise(value) { | ||
return isObjectLike(value) && typeof value['then'] === 'function'; | ||
} | ||
function promiseReduce(values, callbackFn, initialValue) { | ||
let accumulator = initialValue; | ||
for (const value of values) { | ||
accumulator = isPromise(accumulator) | ||
? accumulator.then(resolved => callbackFn(resolved, value)) | ||
: callbackFn(accumulator, value); | ||
} | ||
return accumulator; | ||
} | ||
/** | ||
@@ -454,8 +459,8 @@ * Complete a list value by completing each item in the list with the | ||
const itemType = returnType.ofType; | ||
if ((0, isAsyncIterable_js_1.isAsyncIterable)(result)) { | ||
if ((0, utils_1.isAsyncIterable)(result)) { | ||
const iterator = result[Symbol.asyncIterator](); | ||
return completeAsyncIteratorValue(exeContext, itemType, fieldNodes, info, path, iterator); | ||
} | ||
if (!(0, isIterableObject_js_1.isIterableObject)(result)) { | ||
throw new graphql_1.GraphQLError(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`); | ||
if (!isIterableObject(result)) { | ||
throw (0, utils_1.createGraphQLError)(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`); | ||
} | ||
@@ -471,3 +476,3 @@ // This is specified as a simple map, however we're optimizing the path | ||
let completedItem; | ||
if ((0, isPromise_js_1.isPromise)(item)) { | ||
if (isPromise(item)) { | ||
completedItem = item.then(resolved => completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved)); | ||
@@ -478,3 +483,3 @@ } | ||
} | ||
if ((0, isPromise_js_1.isPromise)(completedItem)) { | ||
if (isPromise(completedItem)) { | ||
containsPromise = true; | ||
@@ -504,4 +509,4 @@ // Note: we don't rely on a `catch` method, but we do expect "thenable" | ||
if (serializedResult == null) { | ||
throw new Error(`Expected \`${(0, inspect_js_1.inspect)(returnType)}.serialize(${(0, inspect_js_1.inspect)(result)})\` to ` + | ||
`return non-nullable value, returned: ${(0, inspect_js_1.inspect)(serializedResult)}`); | ||
throw new Error(`Expected \`${(0, utils_1.inspect)(returnType)}.serialize(${(0, utils_1.inspect)(result)})\` to ` + | ||
`return non-nullable value, returned: ${(0, utils_1.inspect)(serializedResult)}`); | ||
} | ||
@@ -519,3 +524,3 @@ return serializedResult; | ||
const runtimeType = resolveTypeFn(result, contextValue, info, returnType); | ||
if ((0, isPromise_js_1.isPromise)(runtimeType)) { | ||
if (isPromise(runtimeType)) { | ||
return runtimeType.then(resolvedRuntimeType => completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result)); | ||
@@ -527,3 +532,3 @@ } | ||
if (runtimeTypeName == null) { | ||
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 }); | ||
throw (0, utils_1.createGraphQLError)(`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 }); | ||
} | ||
@@ -533,17 +538,17 @@ // releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType` | ||
if ((0, graphql_1.isObjectType)(runtimeTypeName)) { | ||
throw new graphql_1.GraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.'); | ||
throw (0, utils_1.createGraphQLError)('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.'); | ||
} | ||
if (typeof runtimeTypeName !== 'string') { | ||
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 ` + | ||
`value ${(0, inspect_js_1.inspect)(result)}, received "${(0, inspect_js_1.inspect)(runtimeTypeName)}".`); | ||
throw (0, utils_1.createGraphQLError)(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` + | ||
`value ${(0, utils_1.inspect)(result)}, received "${(0, utils_1.inspect)(runtimeTypeName)}".`); | ||
} | ||
const runtimeType = exeContext.schema.getType(runtimeTypeName); | ||
if (runtimeType == null) { | ||
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes }); | ||
throw (0, utils_1.createGraphQLError)(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes }); | ||
} | ||
if (!(0, graphql_1.isObjectType)(runtimeType)) { | ||
throw new graphql_1.GraphQLError(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes }); | ||
throw (0, utils_1.createGraphQLError)(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes }); | ||
} | ||
if (!exeContext.schema.isSubType(returnType, runtimeType)) { | ||
throw new graphql_1.GraphQLError(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes }); | ||
throw (0, utils_1.createGraphQLError)(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes }); | ||
} | ||
@@ -557,3 +562,3 @@ return runtimeType; | ||
// Collect sub-fields to execute to complete this value. | ||
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); | ||
const subFieldNodes = (0, utils_1.collectSubFields)(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes); | ||
// If there is an isTypeOf predicate function, call it with the | ||
@@ -564,3 +569,3 @@ // current result. If isTypeOf returns false, then raise an error rather | ||
const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info); | ||
if ((0, isPromise_js_1.isPromise)(isTypeOf)) { | ||
if (isPromise(isTypeOf)) { | ||
return isTypeOf.then(resolvedIsTypeOf => { | ||
@@ -580,3 +585,3 @@ if (!resolvedIsTypeOf) { | ||
function invalidReturnTypeError(returnType, result, fieldNodes) { | ||
return new graphql_1.GraphQLError(`Expected value of type "${returnType.name}" but got: ${(0, inspect_js_1.inspect)(result)}.`, { | ||
return (0, utils_1.createGraphQLError)(`Expected value of type "${returnType.name}" but got: ${(0, utils_1.inspect)(result)}.`, { | ||
nodes: fieldNodes, | ||
@@ -597,3 +602,3 @@ }); | ||
// First, look for `__typename`. | ||
if ((0, isObjectLike_js_1.isObjectLike)(value) && typeof value['__typename'] === 'string') { | ||
if (isObjectLike(value) && typeof value['__typename'] === 'string') { | ||
return value['__typename']; | ||
@@ -608,3 +613,3 @@ } | ||
const isTypeOfResult = type.isTypeOf(value, contextValue, info); | ||
if ((0, isPromise_js_1.isPromise)(isTypeOfResult)) { | ||
if (isPromise(isTypeOfResult)) { | ||
promisedIsTypeOfResults[i] = isTypeOfResult; | ||
@@ -636,3 +641,3 @@ } | ||
// ensure source is a value for which property access is acceptable. | ||
if ((0, isObjectLike_js_1.isObjectLike)(source) || typeof source === 'function') { | ||
if (isObjectLike(source) || typeof source === 'function') { | ||
const property = source[info.fieldName]; | ||
@@ -676,3 +681,3 @@ if (typeof property === 'function') { | ||
const resultOrStream = createSourceEventStreamImpl(exeContext); | ||
if ((0, isPromise_js_1.isPromise)(resultOrStream)) { | ||
if (isPromise(resultOrStream)) { | ||
return resultOrStream.then(resolvedResultOrStream => mapSourceToResponse(exeContext, resolvedResultOrStream)); | ||
@@ -684,3 +689,3 @@ } | ||
function mapSourceToResponse(exeContext, resultOrStream) { | ||
if (!(0, isAsyncIterable_js_1.isAsyncIterable)(resultOrStream)) { | ||
if (!(0, utils_1.isAsyncIterable)(resultOrStream)) { | ||
return resultOrStream; | ||
@@ -694,3 +699,3 @@ } | ||
// "ExecuteQuery" algorithm, for which `execute` is also used. | ||
return (0, mapAsyncIterator_js_1.mapAsyncIterator)(resultOrStream, (payload) => executeImpl(buildPerEventExecutionContext(exeContext, payload))); | ||
return (0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), (payload) => executeImpl(buildPerEventExecutionContext(exeContext, payload))); | ||
} | ||
@@ -739,3 +744,3 @@ /** | ||
const eventStream = executeSubscription(exeContext); | ||
if ((0, isPromise_js_1.isPromise)(eventStream)) { | ||
if (isPromise(eventStream)) { | ||
return eventStream.then(undefined, error => ({ errors: [error] })); | ||
@@ -754,5 +759,5 @@ } | ||
if (rootType == null) { | ||
throw new graphql_1.GraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
throw (0, utils_1.createGraphQLError)('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
} | ||
const rootFields = (0, collectFields_js_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const rootFields = (0, utils_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const [responseName, fieldNodes] = [...rootFields.entries()][0]; | ||
@@ -762,3 +767,3 @@ const fieldName = fieldNodes[0].name.value; | ||
if (!fieldDef) { | ||
throw new graphql_1.GraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
throw (0, utils_1.createGraphQLError)(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
} | ||
@@ -781,3 +786,3 @@ const path = (0, Path_js_1.addPath)(undefined, responseName, rootType.name); | ||
const result = resolveFn(rootValue, args, contextValue, info); | ||
if ((0, isPromise_js_1.isPromise)(result)) { | ||
if (isPromise(result)) { | ||
return result.then(assertEventStream).then(undefined, error => { | ||
@@ -798,4 +803,4 @@ throw (0, graphql_1.locatedError)(error, fieldNodes, (0, Path_js_1.pathToArray)(path)); | ||
// Assert field returned an event stream, otherwise yield an error. | ||
if (!(0, isAsyncIterable_js_1.isAsyncIterable)(result)) { | ||
throw new graphql_1.GraphQLError('Subscription field must return Async Iterable. ' + `Received: ${(0, inspect_js_1.inspect)(result)}.`); | ||
if (!(0, utils_1.isAsyncIterable)(result)) { | ||
throw (0, utils_1.createGraphQLError)('Subscription field must return Async Iterable. ' + `Received: ${(0, utils_1.inspect)(result)}.`); | ||
} | ||
@@ -802,0 +807,0 @@ return result; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.responsePathAsArray = void 0; | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./collectFields.js"), exports); | ||
tslib_1.__exportStar(require("./execute.js"), exports); | ||
tslib_1.__exportStar(require("./mapAsyncIterator.js"), exports); | ||
tslib_1.__exportStar(require("./values.js"), exports); | ||
var Path_js_1 = require("graphql/jsutils/Path.js"); | ||
Object.defineProperty(exports, "responsePathAsArray", { enumerable: true, get: function () { return Path_js_1.pathToArray; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSourceEventStream = exports.subscribe = void 0; | ||
const utils_1 = require("@graphql-tools/utils"); | ||
const graphql_1 = require("graphql"); | ||
const devAssert_js_1 = require("graphql/jsutils/devAssert.js"); | ||
const inspect_js_1 = require("graphql/jsutils/inspect.js"); | ||
const isAsyncIterable_js_1 = require("graphql/jsutils/isAsyncIterable.js"); | ||
const Path_js_1 = require("graphql/jsutils/Path.js"); | ||
const collectFields_js_1 = require("./collectFields.js"); | ||
const execute_js_1 = require("./execute.js"); | ||
const mapAsyncIterator_js_1 = require("./mapAsyncIterator.js"); | ||
const values_js_1 = require("./values.js"); | ||
@@ -36,6 +32,6 @@ /** | ||
// Temporary for v15 to v16 migration. Remove in v17 | ||
(0, devAssert_js_1.devAssert)(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.'); | ||
console.assert(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.'); | ||
const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, } = args; | ||
const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver); | ||
if (!(0, isAsyncIterable_js_1.isAsyncIterable)(resultOrStream)) { | ||
if (!(0, utils_1.isAsyncIterable)(resultOrStream)) { | ||
return resultOrStream; | ||
@@ -59,3 +55,3 @@ } | ||
// Map every source value to a ExecutionResult value as described above. | ||
return (0, mapAsyncIterator_js_1.mapAsyncIterator)(resultOrStream, mapSourceToResponse); | ||
return (0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), mapSourceToResponse); | ||
} | ||
@@ -113,4 +109,4 @@ exports.subscribe = subscribe; | ||
// Assert field returned an event stream, otherwise yield an error. | ||
if (!(0, isAsyncIterable_js_1.isAsyncIterable)(eventStream)) { | ||
throw new Error('Subscription field must return Async Iterable. ' + `Received: ${(0, inspect_js_1.inspect)(eventStream)}.`); | ||
if (!(0, utils_1.isAsyncIterable)(eventStream)) { | ||
throw new Error('Subscription field must return Async Iterable. ' + `Received: ${(0, utils_1.inspect)(eventStream)}.`); | ||
} | ||
@@ -134,5 +130,5 @@ return eventStream; | ||
if (rootType == null) { | ||
throw new graphql_1.GraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
throw (0, utils_1.createGraphQLError)('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
} | ||
const rootFields = (0, collectFields_js_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const rootFields = (0, utils_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const [responseName, fieldNodes] = [...rootFields.entries()][0]; | ||
@@ -142,3 +138,3 @@ const fieldDef = (0, execute_js_1.getFieldDef)(schema, rootType, fieldNodes[0]); | ||
const fieldName = fieldNodes[0].name.value; | ||
throw new graphql_1.GraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
throw (0, utils_1.createGraphQLError)(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
} | ||
@@ -145,0 +141,0 @@ const path = (0, Path_js_1.addPath)(undefined, responseName, rootType.name); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDirectiveValues = exports.getArgumentValues = exports.getVariableValues = void 0; | ||
const inspect_js_1 = require("graphql/jsutils/inspect.js"); | ||
const keyMap_js_1 = require("graphql/jsutils/keyMap.js"); | ||
const printPathArray_js_1 = require("graphql/jsutils/printPathArray.js"); | ||
const graphql_1 = require("graphql"); | ||
const utils_1 = require("@graphql-tools/utils"); | ||
/** | ||
@@ -23,3 +22,3 @@ * Prepares an object map of variableValues of the correct type based on the | ||
if (maxErrors != null && errors.length >= maxErrors) { | ||
throw new graphql_1.GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.'); | ||
throw (0, utils_1.createGraphQLError)('Too many errors processing variables, error limit reached. Execution aborted.'); | ||
} | ||
@@ -48,3 +47,3 @@ errors.push(error); | ||
const varTypeStr = (0, graphql_1.print)(varDefNode.type); | ||
onError(new graphql_1.GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type })); | ||
onError((0, utils_1.createGraphQLError)(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type })); | ||
continue; | ||
@@ -57,4 +56,4 @@ } | ||
else if ((0, graphql_1.isNonNullType)(varType)) { | ||
const varTypeStr = (0, inspect_js_1.inspect)(varType); | ||
onError(new graphql_1.GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, { | ||
const varTypeStr = (0, utils_1.inspect)(varType); | ||
onError((0, utils_1.createGraphQLError)(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, { | ||
nodes: varDefNode, | ||
@@ -67,4 +66,4 @@ })); | ||
if (value === null && (0, graphql_1.isNonNullType)(varType)) { | ||
const varTypeStr = (0, inspect_js_1.inspect)(varType); | ||
onError(new graphql_1.GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, { | ||
const varTypeStr = (0, utils_1.inspect)(varType); | ||
onError((0, utils_1.createGraphQLError)(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, { | ||
nodes: varDefNode, | ||
@@ -75,7 +74,7 @@ })); | ||
coercedValues[varName] = (0, graphql_1.coerceInputValue)(value, varType, (path, invalidValue, error) => { | ||
let prefix = `Variable "$${varName}" got invalid value ` + (0, inspect_js_1.inspect)(invalidValue); | ||
let prefix = `Variable "$${varName}" got invalid value ` + (0, utils_1.inspect)(invalidValue); | ||
if (path.length > 0) { | ||
prefix += ` at "${varName}${(0, printPathArray_js_1.printPathArray)(path)}"`; | ||
} | ||
onError(new graphql_1.GraphQLError(prefix + '; ' + error.message, { | ||
onError((0, utils_1.createGraphQLError)(prefix + '; ' + error.message, { | ||
nodes: varDefNode, | ||
@@ -102,3 +101,6 @@ originalError: error.originalError, | ||
const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : []; | ||
const argNodeMap = (0, keyMap_js_1.keyMap)(argumentNodes, arg => arg.name.value); | ||
const argNodeMap = Object.create(null); | ||
for (const arg of argumentNodes) { | ||
argNodeMap[arg.name.value] = arg.value; | ||
} | ||
for (const argDef of def.args) { | ||
@@ -113,3 +115,3 @@ const name = argDef.name; | ||
else if ((0, graphql_1.isNonNullType)(argType)) { | ||
throw new graphql_1.GraphQLError(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` + 'was not provided.', { | ||
throw (0, utils_1.createGraphQLError)(`Argument "${name}" of required type "${(0, utils_1.inspect)(argType)}" ` + 'was not provided.', { | ||
nodes: node, | ||
@@ -129,3 +131,3 @@ }); | ||
else if ((0, graphql_1.isNonNullType)(argType)) { | ||
throw new graphql_1.GraphQLError(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` + | ||
throw (0, utils_1.createGraphQLError)(`Argument "${name}" of required type "${(0, utils_1.inspect)(argType)}" ` + | ||
`was provided the variable "$${variableName}" which was not provided a runtime value.`, { nodes: valueNode }); | ||
@@ -138,3 +140,3 @@ } | ||
if (isNull && (0, graphql_1.isNonNullType)(argType)) { | ||
throw new graphql_1.GraphQLError(`Argument "${name}" of non-null type "${(0, inspect_js_1.inspect)(argType)}" ` + 'must not be null.', { | ||
throw (0, utils_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, utils_1.inspect)(argType)}" ` + 'must not be null.', { | ||
nodes: valueNode, | ||
@@ -148,3 +150,3 @@ }); | ||
// continue with an invalid argument value. | ||
throw new graphql_1.GraphQLError(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, { nodes: valueNode }); | ||
throw (0, utils_1.createGraphQLError)(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, { nodes: valueNode }); | ||
} | ||
@@ -151,0 +153,0 @@ coercedValues[name] = coercedValue; |
@@ -1,25 +0,6 @@ | ||
import { devAssert } from 'graphql/jsutils/devAssert.js'; | ||
import { inspect } from 'graphql/jsutils/inspect.js'; | ||
import { invariant } from 'graphql/jsutils/invariant.js'; | ||
import { isAsyncIterable } from 'graphql/jsutils/isAsyncIterable.js'; | ||
import { isIterableObject } from 'graphql/jsutils/isIterableObject.js'; | ||
import { isObjectLike } from 'graphql/jsutils/isObjectLike.js'; | ||
import { isPromise } from 'graphql/jsutils/isPromise.js'; | ||
import { memoize3 } from 'graphql/jsutils/memoize3.js'; | ||
import { addPath, pathToArray } from 'graphql/jsutils/Path.js'; | ||
import { promiseForObject } from 'graphql/jsutils/promiseForObject.js'; | ||
import { promiseReduce } from 'graphql/jsutils/promiseReduce.js'; | ||
import { locatedError, GraphQLError, OperationTypeNode, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql'; | ||
import { collectFields, collectSubfields as _collectSubfields } from './collectFields.js'; | ||
import { mapAsyncIterator } from './mapAsyncIterator.js'; | ||
import { locatedError, OperationTypeNode, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql'; | ||
import { getArgumentValues, getVariableValues } from './values.js'; | ||
// This file contains a lot of such errors but we plan to refactor it anyway | ||
// so just disable it for entire file. | ||
import { collectFields, collectSubFields, createGraphQLError, inspect, isAsyncIterable, mapAsyncIterator, } from '@graphql-tools/utils'; | ||
/** | ||
* A memoized collection of relevant subfields with regard to the return | ||
* type. Memoizing ensures the subfields are not repeatedly calculated, which | ||
* saves overhead when resolving lists of values. | ||
*/ | ||
const collectSubfields = memoize3((exeContext, returnType, fieldNodes) => _collectSubfields(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes)); | ||
/** | ||
* Implements the "Executing requests" section of the GraphQL specification. | ||
@@ -98,7 +79,7 @@ * | ||
export function assertValidExecutionArguments(schema, document, rawVariableValues) { | ||
devAssert(!!document, 'Must provide document.'); | ||
console.assert(!!document, 'Must provide document.'); | ||
// If the schema used for execution is invalid, throw an error. | ||
assertValidSchema(schema); | ||
// Variables, if provided, must be an object. | ||
devAssert(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.'); | ||
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.'); | ||
} | ||
@@ -126,3 +107,3 @@ /** | ||
if (operation !== undefined) { | ||
return [new GraphQLError('Must provide operation name if query contains multiple operations.')]; | ||
return [createGraphQLError('Must provide operation name if query contains multiple operations.')]; | ||
} | ||
@@ -144,5 +125,5 @@ operation = definition; | ||
if (operationName != null) { | ||
return [new GraphQLError(`Unknown operation named "${operationName}".`)]; | ||
return [createGraphQLError(`Unknown operation named "${operationName}".`)]; | ||
} | ||
return [new GraphQLError('Must provide an operation.')]; | ||
return [createGraphQLError('Must provide an operation.')]; | ||
} | ||
@@ -185,3 +166,3 @@ // FIXME: https://github.com/graphql/graphql-js/issues/2203 | ||
if (rootType == null) { | ||
throw new GraphQLError(`Schema is not configured to execute ${operation.operation} operation.`, { | ||
throw createGraphQLError(`Schema is not configured to execute ${operation.operation} operation.`, { | ||
nodes: operation, | ||
@@ -248,3 +229,9 @@ }); | ||
// same map, but with any promises replaced with the values they resolved to. | ||
return promiseForObject(results); | ||
return Promise.all(Object.values(results)).then(resolvedValues => { | ||
const resolvedObject = Object.create(null); | ||
for (const [i, key] of Object.keys(results).entries()) { | ||
resolvedObject[key] = resolvedValues[i]; | ||
} | ||
return resolvedObject; | ||
}); | ||
} | ||
@@ -389,3 +376,3 @@ /** | ||
// Not reachable, all possible output types have been considered. | ||
invariant(false, 'Cannot complete value of unexpected output type: ' + inspect(returnType)); | ||
console.assert(false, 'Cannot complete value of unexpected output type: ' + inspect(returnType)); | ||
} | ||
@@ -431,2 +418,20 @@ /** | ||
} | ||
function isIterableObject(value) { | ||
return value != null && typeof value === 'object' && Symbol.iterator in value; | ||
} | ||
function isObjectLike(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
function isPromise(value) { | ||
return isObjectLike(value) && typeof value['then'] === 'function'; | ||
} | ||
function promiseReduce(values, callbackFn, initialValue) { | ||
let accumulator = initialValue; | ||
for (const value of values) { | ||
accumulator = isPromise(accumulator) | ||
? accumulator.then(resolved => callbackFn(resolved, value)) | ||
: callbackFn(accumulator, value); | ||
} | ||
return accumulator; | ||
} | ||
/** | ||
@@ -443,3 +448,3 @@ * Complete a list value by completing each item in the list with the | ||
if (!isIterableObject(result)) { | ||
throw new GraphQLError(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`); | ||
throw createGraphQLError(`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`); | ||
} | ||
@@ -507,3 +512,3 @@ // This is specified as a simple map, however we're optimizing the path | ||
if (runtimeTypeName == null) { | ||
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 }); | ||
throw createGraphQLError(`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 }); | ||
} | ||
@@ -513,6 +518,6 @@ // releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType` | ||
if (isObjectType(runtimeTypeName)) { | ||
throw new GraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.'); | ||
throw createGraphQLError('Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.'); | ||
} | ||
if (typeof runtimeTypeName !== 'string') { | ||
throw new GraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` + | ||
throw createGraphQLError(`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` + | ||
`value ${inspect(result)}, received "${inspect(runtimeTypeName)}".`); | ||
@@ -522,9 +527,9 @@ } | ||
if (runtimeType == null) { | ||
throw new GraphQLError(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes }); | ||
throw createGraphQLError(`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`, { nodes: fieldNodes }); | ||
} | ||
if (!isObjectType(runtimeType)) { | ||
throw new GraphQLError(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes }); | ||
throw createGraphQLError(`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`, { nodes: fieldNodes }); | ||
} | ||
if (!exeContext.schema.isSubType(returnType, runtimeType)) { | ||
throw new GraphQLError(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes }); | ||
throw createGraphQLError(`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`, { nodes: fieldNodes }); | ||
} | ||
@@ -538,3 +543,3 @@ return runtimeType; | ||
// Collect sub-fields to execute to complete this value. | ||
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); | ||
const subFieldNodes = collectSubFields(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes); | ||
// If there is an isTypeOf predicate function, call it with the | ||
@@ -560,3 +565,3 @@ // current result. If isTypeOf returns false, then raise an error rather | ||
function invalidReturnTypeError(returnType, result, fieldNodes) { | ||
return new GraphQLError(`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`, { | ||
return createGraphQLError(`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`, { | ||
nodes: fieldNodes, | ||
@@ -666,3 +671,3 @@ }); | ||
// "ExecuteQuery" algorithm, for which `execute` is also used. | ||
return mapAsyncIterator(resultOrStream, (payload) => executeImpl(buildPerEventExecutionContext(exeContext, payload))); | ||
return mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), (payload) => executeImpl(buildPerEventExecutionContext(exeContext, payload))); | ||
} | ||
@@ -724,3 +729,3 @@ /** | ||
if (rootType == null) { | ||
throw new GraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
throw createGraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
} | ||
@@ -732,3 +737,3 @@ const rootFields = collectFields(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
if (!fieldDef) { | ||
throw new GraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
throw createGraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
} | ||
@@ -768,3 +773,3 @@ const path = addPath(undefined, responseName, rootType.name); | ||
if (!isAsyncIterable(result)) { | ||
throw new GraphQLError('Subscription field must return Async Iterable. ' + `Received: ${inspect(result)}.`); | ||
throw createGraphQLError('Subscription field must return Async Iterable. ' + `Received: ${inspect(result)}.`); | ||
} | ||
@@ -771,0 +776,0 @@ return result; |
@@ -1,5 +0,2 @@ | ||
export * from './collectFields.js'; | ||
export * from './execute.js'; | ||
export * from './mapAsyncIterator.js'; | ||
export * from './values.js'; | ||
export { pathToArray as responsePathAsArray } from 'graphql/jsutils/Path.js'; |
@@ -0,9 +1,5 @@ | ||
import { collectFields, mapAsyncIterator, inspect, isAsyncIterable, createGraphQLError, } from '@graphql-tools/utils'; | ||
import { GraphQLError, locatedError } from 'graphql'; | ||
import { devAssert } from 'graphql/jsutils/devAssert.js'; | ||
import { inspect } from 'graphql/jsutils/inspect.js'; | ||
import { isAsyncIterable } from 'graphql/jsutils/isAsyncIterable.js'; | ||
import { addPath, pathToArray } from 'graphql/jsutils/Path.js'; | ||
import { collectFields } from './collectFields.js'; | ||
import { assertValidExecutionArguments, buildExecutionContext, buildResolveInfo, execute, getFieldDef, } from './execute.js'; | ||
import { mapAsyncIterator } from './mapAsyncIterator.js'; | ||
import { getArgumentValues } from './values.js'; | ||
@@ -33,3 +29,3 @@ /** | ||
// Temporary for v15 to v16 migration. Remove in v17 | ||
devAssert(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.'); | ||
console.assert(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.'); | ||
const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, } = args; | ||
@@ -56,3 +52,3 @@ const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver); | ||
// Map every source value to a ExecutionResult value as described above. | ||
return mapAsyncIterator(resultOrStream, mapSourceToResponse); | ||
return mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), mapSourceToResponse); | ||
} | ||
@@ -128,3 +124,3 @@ /** | ||
if (rootType == null) { | ||
throw new GraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
throw createGraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation }); | ||
} | ||
@@ -136,3 +132,3 @@ const rootFields = collectFields(schema, fragments, variableValues, rootType, operation.selectionSet); | ||
const fieldName = fieldNodes[0].name.value; | ||
throw new GraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
throw createGraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes }); | ||
} | ||
@@ -139,0 +135,0 @@ const path = addPath(undefined, responseName, rootType.name); |
@@ -1,5 +0,4 @@ | ||
import { inspect } from 'graphql/jsutils/inspect.js'; | ||
import { keyMap } from 'graphql/jsutils/keyMap.js'; | ||
import { printPathArray } from 'graphql/jsutils/printPathArray.js'; | ||
import { GraphQLError, Kind, print, isInputType, isNonNullType, coerceInputValue, typeFromAST, valueFromAST, } from 'graphql'; | ||
import { Kind, print, isInputType, isNonNullType, coerceInputValue, typeFromAST, valueFromAST, } from 'graphql'; | ||
import { createGraphQLError, inspect } from '@graphql-tools/utils'; | ||
/** | ||
@@ -20,3 +19,3 @@ * Prepares an object map of variableValues of the correct type based on the | ||
if (maxErrors != null && errors.length >= maxErrors) { | ||
throw new GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.'); | ||
throw createGraphQLError('Too many errors processing variables, error limit reached. Execution aborted.'); | ||
} | ||
@@ -44,3 +43,3 @@ errors.push(error); | ||
const varTypeStr = print(varDefNode.type); | ||
onError(new GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type })); | ||
onError(createGraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, { nodes: varDefNode.type })); | ||
continue; | ||
@@ -54,3 +53,3 @@ } | ||
const varTypeStr = inspect(varType); | ||
onError(new GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, { | ||
onError(createGraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, { | ||
nodes: varDefNode, | ||
@@ -64,3 +63,3 @@ })); | ||
const varTypeStr = inspect(varType); | ||
onError(new GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, { | ||
onError(createGraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, { | ||
nodes: varDefNode, | ||
@@ -75,3 +74,3 @@ })); | ||
} | ||
onError(new GraphQLError(prefix + '; ' + error.message, { | ||
onError(createGraphQLError(prefix + '; ' + error.message, { | ||
nodes: varDefNode, | ||
@@ -98,3 +97,6 @@ originalError: error.originalError, | ||
const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : []; | ||
const argNodeMap = keyMap(argumentNodes, arg => arg.name.value); | ||
const argNodeMap = Object.create(null); | ||
for (const arg of argumentNodes) { | ||
argNodeMap[arg.name.value] = arg.value; | ||
} | ||
for (const argDef of def.args) { | ||
@@ -109,3 +111,3 @@ const name = argDef.name; | ||
else if (isNonNullType(argType)) { | ||
throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', { | ||
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', { | ||
nodes: node, | ||
@@ -125,3 +127,3 @@ }); | ||
else if (isNonNullType(argType)) { | ||
throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + | ||
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + | ||
`was provided the variable "$${variableName}" which was not provided a runtime value.`, { nodes: valueNode }); | ||
@@ -134,3 +136,3 @@ } | ||
if (isNull && isNonNullType(argType)) { | ||
throw new GraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', { | ||
throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', { | ||
nodes: valueNode, | ||
@@ -144,3 +146,3 @@ }); | ||
// continue with an invalid argument value. | ||
throw new GraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, { nodes: valueNode }); | ||
throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, { nodes: valueNode }); | ||
} | ||
@@ -147,0 +149,0 @@ coercedValues[name] = coercedValue; |
{ | ||
"name": "@graphql-tools/executor", | ||
"version": "0.0.1-alpha-20221025014654-e3be5659", | ||
"version": "0.0.1-alpha-20221025154355-1d847f5a", | ||
"sideEffects": false, | ||
@@ -8,2 +8,5 @@ "peerDependencies": { | ||
}, | ||
"dependencies": { | ||
"@graphql-tools/utils": "8.12.0" | ||
}, | ||
"repository": { | ||
@@ -10,0 +13,0 @@ "type": "git", |
@@ -1,6 +0,4 @@ | ||
import type { Maybe } from 'graphql/jsutils/Maybe.js'; | ||
import type { ObjMap } from 'graphql/jsutils/ObjMap.js'; | ||
import type { Path } from 'graphql/jsutils/Path.js'; | ||
import type { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue.js'; | ||
import { GraphQLFormattedError, GraphQLError, DocumentNode, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema } from 'graphql'; | ||
import { Maybe } from '@graphql-tools/utils'; | ||
/** | ||
@@ -33,3 +31,3 @@ * Terminology | ||
schema: GraphQLSchema; | ||
fragments: ObjMap<FragmentDefinitionNode>; | ||
fragments: Record<string, FragmentDefinitionNode>; | ||
rootValue: unknown; | ||
@@ -53,3 +51,3 @@ contextValue: unknown; | ||
*/ | ||
export interface ExecutionResult<TData = ObjMap<unknown>, TExtensions = ObjMap<unknown>> { | ||
export interface ExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> { | ||
errors?: ReadonlyArray<GraphQLError>; | ||
@@ -59,3 +57,3 @@ data?: TData | null; | ||
} | ||
export interface FormattedExecutionResult<TData = ObjMap<unknown>, TExtensions = ObjMap<unknown>> { | ||
export interface FormattedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> { | ||
errors?: ReadonlyArray<GraphQLFormattedError>; | ||
@@ -119,2 +117,3 @@ data?: TData | null; | ||
export declare function buildResolveInfo(exeContext: ExecutionContext, fieldDef: GraphQLField<unknown, unknown>, fieldNodes: ReadonlyArray<FieldNode>, parentType: GraphQLObjectType, path: Path): GraphQLResolveInfo; | ||
declare type PromiseOrValue<T> = Promise<T> | T; | ||
/** | ||
@@ -159,3 +158,3 @@ * If a resolveType function is not given, then a default resolve behavior is | ||
*/ | ||
export declare function subscribe(args: ExecutionArgs): PromiseOrValue<AsyncGenerator<ExecutionResult, void, void> | ExecutionResult>; | ||
export declare function subscribe(args: ExecutionArgs): PromiseOrValue<AsyncIterable<ExecutionResult> | ExecutionResult>; | ||
/** | ||
@@ -202,1 +201,2 @@ * Implements the "CreateSourceEventStream" algorithm described in the | ||
export declare function getFieldDef(schema: GraphQLSchema, parentType: GraphQLObjectType, fieldNode: FieldNode): Maybe<GraphQLField<unknown, unknown>>; | ||
export {}; |
@@ -1,5 +0,2 @@ | ||
export * from './collectFields.js'; | ||
export * from './execute.js'; | ||
export * from './mapAsyncIterator.js'; | ||
export * from './values.js'; | ||
export { pathToArray as responsePathAsArray } from 'graphql/jsutils/Path.js'; |
@@ -0,3 +1,3 @@ | ||
import { Maybe } from '@graphql-tools/utils'; | ||
import { DocumentNode, GraphQLFieldResolver, GraphQLSchema } from 'graphql'; | ||
import type { Maybe } from 'graphql/jsutils/Maybe.js'; | ||
import type { ExecutionArgs, ExecutionResult } from './execute.js'; | ||
@@ -25,3 +25,3 @@ /** | ||
*/ | ||
export declare function subscribe(args: ExecutionArgs): Promise<AsyncGenerator<ExecutionResult, void, void> | ExecutionResult>; | ||
export declare function subscribe(args: ExecutionArgs): Promise<AsyncIterable<ExecutionResult> | ExecutionResult>; | ||
/** | ||
@@ -28,0 +28,0 @@ * Implements the "CreateSourceEventStream" algorithm described in the |
@@ -1,4 +0,3 @@ | ||
import type { Maybe } from 'graphql/jsutils/Maybe.js'; | ||
import type { ObjMap } from 'graphql/jsutils/ObjMap.js'; | ||
import { GraphQLError, DirectiveNode, FieldNode, VariableDefinitionNode, GraphQLField, GraphQLDirective, GraphQLSchema } from 'graphql'; | ||
import { Maybe } from '@graphql-tools/utils'; | ||
declare type CoercedVariableValues = { | ||
@@ -35,3 +34,3 @@ errors: ReadonlyArray<GraphQLError>; | ||
*/ | ||
export declare function getArgumentValues(def: GraphQLField<unknown, unknown> | GraphQLDirective, node: FieldNode | DirectiveNode, variableValues?: Maybe<ObjMap<unknown>>): { | ||
export declare function getArgumentValues(def: GraphQLField<unknown, unknown> | GraphQLDirective, node: FieldNode | DirectiveNode, variableValues?: Maybe<Record<string, unknown>>): { | ||
[argument: string]: unknown; | ||
@@ -52,5 +51,5 @@ }; | ||
readonly directives?: ReadonlyArray<DirectiveNode>; | ||
}, variableValues?: Maybe<ObjMap<unknown>>): undefined | { | ||
}, variableValues?: Maybe<Record<string, unknown>>): undefined | { | ||
[argument: string]: unknown; | ||
}; | ||
export {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135192
2
23
2553
+ Added@graphql-tools/utils@8.12.0
+ Added@graphql-tools/utils@8.12.0(transitive)
+ Addedtslib@2.8.1(transitive)