summaryrefslogtreecommitdiff
path: root/school/node_modules/graphql/execution
diff options
context:
space:
mode:
Diffstat (limited to 'school/node_modules/graphql/execution')
-rw-r--r--school/node_modules/graphql/execution/execute.d.ts195
-rw-r--r--school/node_modules/graphql/execution/execute.js866
-rw-r--r--school/node_modules/graphql/execution/execute.js.flow1246
-rw-r--r--school/node_modules/graphql/execution/execute.mjs847
-rw-r--r--school/node_modules/graphql/execution/index.d.ts13
-rw-r--r--school/node_modules/graphql/execution/index.js47
-rw-r--r--school/node_modules/graphql/execution/index.js.flow17
-rw-r--r--school/node_modules/graphql/execution/index.mjs3
-rw-r--r--school/node_modules/graphql/execution/values.d.ts65
-rw-r--r--school/node_modules/graphql/execution/values.js228
-rw-r--r--school/node_modules/graphql/execution/values.js.flow267
-rw-r--r--school/node_modules/graphql/execution/values.mjs206
12 files changed, 4000 insertions, 0 deletions
diff --git a/school/node_modules/graphql/execution/execute.d.ts b/school/node_modules/graphql/execution/execute.d.ts
new file mode 100644
index 0000000..a20db8c
--- /dev/null
+++ b/school/node_modules/graphql/execution/execute.d.ts
@@ -0,0 +1,195 @@
+import { Maybe } from '../jsutils/Maybe';
+
+import { PromiseOrValue } from '../jsutils/PromiseOrValue';
+import { Path } from '../jsutils/Path';
+
+import { GraphQLError } from '../error/GraphQLError';
+import { GraphQLFormattedError } from '../error/formatError';
+
+import {
+ DocumentNode,
+ OperationDefinitionNode,
+ SelectionSetNode,
+ FieldNode,
+ FragmentDefinitionNode,
+} from '../language/ast';
+import { GraphQLSchema } from '../type/schema';
+import {
+ GraphQLField,
+ GraphQLFieldResolver,
+ GraphQLResolveInfo,
+ GraphQLTypeResolver,
+ GraphQLObjectType,
+} from '../type/definition';
+
+/**
+ * Data that must be available at all points during query execution.
+ *
+ * Namely, schema of the type system that is currently executing,
+ * and the fragments defined in the query document
+ */
+export interface ExecutionContext {
+ schema: GraphQLSchema;
+ fragments: { [key: string]: FragmentDefinitionNode };
+ rootValue: any;
+ contextValue: any;
+ operation: OperationDefinitionNode;
+ variableValues: { [key: string]: any };
+ fieldResolver: GraphQLFieldResolver<any, any>;
+ errors: Array<GraphQLError>;
+}
+
+/**
+ * The result of GraphQL execution.
+ *
+ * - `errors` is included when any errors occurred as a non-empty array.
+ * - `data` is the result of a successful execution of the query.
+ * - `extensions` is reserved for adding non-standard properties.
+ */
+export interface ExecutionResult<
+ TData = { [key: string]: any },
+ TExtensions = { [key: string]: any }
+> {
+ errors?: ReadonlyArray<GraphQLError>;
+ // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
+ data?: TData | null;
+ extensions?: TExtensions;
+}
+
+export interface FormattedExecutionResult<
+ TData = { [key: string]: any },
+ TExtensions = { [key: string]: any }
+> {
+ errors?: ReadonlyArray<GraphQLFormattedError>;
+ // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
+ data?: TData | null;
+ extensions?: TExtensions;
+}
+
+export interface ExecutionArgs {
+ schema: GraphQLSchema;
+ document: DocumentNode;
+ rootValue?: any;
+ contextValue?: any;
+ variableValues?: Maybe<{ [key: string]: any }>;
+ operationName?: Maybe<string>;
+ fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
+}
+
+/**
+ * Implements the "Evaluating requests" section of the GraphQL specification.
+ *
+ * Returns either a synchronous ExecutionResult (if all encountered resolvers
+ * are synchronous), or a Promise of an ExecutionResult that will eventually be
+ * resolved and never rejected.
+ *
+ * If the arguments to this function do not result in a legal execution context,
+ * a GraphQLError will be thrown immediately explaining the invalid input.
+ *
+ * Accepts either an object with named arguments, or individual arguments.
+ */
+export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult>;
+export function execute(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rootValue?: any,
+ contextValue?: any,
+ variableValues?: Maybe<{ [key: string]: any }>,
+ operationName?: Maybe<string>,
+ fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
+): PromiseOrValue<ExecutionResult>;
+
+/**
+ * Also implements the "Evaluating requests" section of the GraphQL specification.
+ * However, it guarantees to complete synchronously (or throw an error) assuming
+ * that all field resolvers are also synchronous.
+ */
+export function executeSync(args: ExecutionArgs): ExecutionResult;
+
+/**
+ * Essential assertions before executing to provide developer feedback for
+ * improper use of the GraphQL library.
+ */
+export function assertValidExecutionArguments(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rawVariableValues: Maybe<{ [key: string]: any }>,
+): void;
+
+/**
+ * Constructs a ExecutionContext object from the arguments passed to
+ * execute, which we will pass throughout the other execution methods.
+ *
+ * Throws a GraphQLError if a valid execution context cannot be created.
+ */
+export function buildExecutionContext(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rootValue: any,
+ contextValue: any,
+ rawVariableValues: Maybe<{ [key: string]: any }>,
+ operationName: Maybe<string>,
+ fieldResolver: Maybe<GraphQLFieldResolver<any, any>>,
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
+): ReadonlyArray<GraphQLError> | ExecutionContext;
+
+/**
+ * Given a selectionSet, adds all of the fields in that selection to
+ * the passed in map of fields, and returns it at the end.
+ *
+ * CollectFields requires the "runtime type" of an object. For a field which
+ * returns an Interface or Union type, the "runtime type" will be the actual
+ * Object type returned by that field.
+ */
+export function collectFields(
+ exeContext: ExecutionContext,
+ runtimeType: GraphQLObjectType,
+ selectionSet: SelectionSetNode,
+ fields: { [key: string]: Array<FieldNode> },
+ visitedFragmentNames: { [key: string]: boolean },
+): { [key: string]: Array<FieldNode> };
+
+export function buildResolveInfo(
+ exeContext: ExecutionContext,
+ fieldDef: GraphQLField<any, any>,
+ fieldNodes: ReadonlyArray<FieldNode>,
+ parentType: GraphQLObjectType,
+ path: Path,
+): GraphQLResolveInfo;
+
+/**
+ * If a resolveType function is not given, then a default resolve behavior is
+ * used which attempts two strategies:
+ *
+ * First, See if the provided value has a `__typename` field defined, if so, use
+ * that value as name of the resolved type.
+ *
+ * Otherwise, test each possible type for the abstract type by calling
+ * isTypeOf for the object being coerced, returning the first type that matches.
+ */
+export const defaultTypeResolver: GraphQLTypeResolver<any, any>;
+
+/**
+ * If a resolve function is not given, then a default resolve behavior is used
+ * which takes the property of the source object of the same name as the field
+ * and returns it as the result, or if it's a function, returns the result
+ * of calling that function while passing along args and context.
+ */
+export const defaultFieldResolver: GraphQLFieldResolver<any, any>;
+
+/**
+ * This method looks up the field on the given type definition.
+ * It has special casing for the two introspection fields, __schema
+ * and __typename. __typename is special because it can always be
+ * queried as a field, even in situations where no other fields
+ * are allowed, like on a Union. __schema could get automatically
+ * added to the query type, but that would require mutating type
+ * definitions, which would cause issues.
+ */
+export function getFieldDef(
+ schema: GraphQLSchema,
+ parentType: GraphQLObjectType,
+ fieldName: string,
+): Maybe<GraphQLField<any, any>>;
diff --git a/school/node_modules/graphql/execution/execute.js b/school/node_modules/graphql/execution/execute.js
new file mode 100644
index 0000000..cf4e628
--- /dev/null
+++ b/school/node_modules/graphql/execution/execute.js
@@ -0,0 +1,866 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.execute = execute;
+exports.executeSync = executeSync;
+exports.assertValidExecutionArguments = assertValidExecutionArguments;
+exports.buildExecutionContext = buildExecutionContext;
+exports.collectFields = collectFields;
+exports.buildResolveInfo = buildResolveInfo;
+exports.getFieldDef = getFieldDef;
+exports.defaultFieldResolver = exports.defaultTypeResolver = void 0;
+
+var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
+
+var _memoize = _interopRequireDefault(require("../jsutils/memoize3.js"));
+
+var _invariant = _interopRequireDefault(require("../jsutils/invariant.js"));
+
+var _devAssert = _interopRequireDefault(require("../jsutils/devAssert.js"));
+
+var _isPromise = _interopRequireDefault(require("../jsutils/isPromise.js"));
+
+var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike.js"));
+
+var _safeArrayFrom = _interopRequireDefault(require("../jsutils/safeArrayFrom.js"));
+
+var _promiseReduce = _interopRequireDefault(require("../jsutils/promiseReduce.js"));
+
+var _promiseForObject = _interopRequireDefault(require("../jsutils/promiseForObject.js"));
+
+var _Path = require("../jsutils/Path.js");
+
+var _GraphQLError = require("../error/GraphQLError.js");
+
+var _locatedError = require("../error/locatedError.js");
+
+var _kinds = require("../language/kinds.js");
+
+var _validate = require("../type/validate.js");
+
+var _introspection = require("../type/introspection.js");
+
+var _directives = require("../type/directives.js");
+
+var _definition = require("../type/definition.js");
+
+var _typeFromAST = require("../utilities/typeFromAST.js");
+
+var _getOperationRootType = require("../utilities/getOperationRootType.js");
+
+var _values = require("./values.js");
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+function execute(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
+ /* eslint-enable no-redeclare */
+ // Extract arguments from object args if provided.
+ return arguments.length === 1 ? executeImpl(argsOrSchema) : executeImpl({
+ schema: argsOrSchema,
+ document: document,
+ rootValue: rootValue,
+ contextValue: contextValue,
+ variableValues: variableValues,
+ operationName: operationName,
+ fieldResolver: fieldResolver,
+ typeResolver: typeResolver
+ });
+}
+/**
+ * Also implements the "Evaluating requests" section of the GraphQL specification.
+ * However, it guarantees to complete synchronously (or throw an error) assuming
+ * that all field resolvers are also synchronous.
+ */
+
+
+function executeSync(args) {
+ var result = executeImpl(args); // Assert that the execution was synchronous.
+
+ if ((0, _isPromise.default)(result)) {
+ throw new Error('GraphQL execution failed to complete synchronously.');
+ }
+
+ return result;
+}
+
+function executeImpl(args) {
+ var schema = args.schema,
+ document = args.document,
+ rootValue = args.rootValue,
+ contextValue = args.contextValue,
+ variableValues = args.variableValues,
+ operationName = args.operationName,
+ fieldResolver = args.fieldResolver,
+ typeResolver = args.typeResolver; // If arguments are missing or incorrect, throw an error.
+
+ assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
+ // a "Response" with only errors is returned.
+
+ var exeContext = buildExecutionContext(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver); // Return early errors if execution context failed.
+
+ if (Array.isArray(exeContext)) {
+ return {
+ errors: exeContext
+ };
+ } // Return a Promise that will eventually resolve to the data described by
+ // The "Response" section of the GraphQL specification.
+ //
+ // If errors are encountered while executing a GraphQL field, only that
+ // field and its descendants will be omitted, and sibling fields will still
+ // be executed. An execution which encounters errors will still result in a
+ // resolved Promise.
+
+
+ var data = executeOperation(exeContext, exeContext.operation, rootValue);
+ return buildResponse(exeContext, data);
+}
+/**
+ * Given a completed execution context and data, build the { errors, data }
+ * response defined by the "Response" section of the GraphQL specification.
+ */
+
+
+function buildResponse(exeContext, data) {
+ if ((0, _isPromise.default)(data)) {
+ return data.then(function (resolved) {
+ return buildResponse(exeContext, resolved);
+ });
+ }
+
+ return exeContext.errors.length === 0 ? {
+ data: data
+ } : {
+ errors: exeContext.errors,
+ data: data
+ };
+}
+/**
+ * Essential assertions before executing to provide developer feedback for
+ * improper use of the GraphQL library.
+ *
+ * @internal
+ */
+
+
+function assertValidExecutionArguments(schema, document, rawVariableValues) {
+ document || (0, _devAssert.default)(0, 'Must provide document.'); // If the schema used for execution is invalid, throw an error.
+
+ (0, _validate.assertValidSchema)(schema); // Variables, if provided, must be an object.
+
+ rawVariableValues == null || (0, _isObjectLike.default)(rawVariableValues) || (0, _devAssert.default)(0, '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.');
+}
+/**
+ * Constructs a ExecutionContext object from the arguments passed to
+ * execute, which we will pass throughout the other execution methods.
+ *
+ * Throws a GraphQLError if a valid execution context cannot be created.
+ *
+ * @internal
+ */
+
+
+function buildExecutionContext(schema, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
+ var _definition$name, _operation$variableDe;
+
+ var operation;
+ var fragments = Object.create(null);
+
+ for (var _i2 = 0, _document$definitions2 = document.definitions; _i2 < _document$definitions2.length; _i2++) {
+ var definition = _document$definitions2[_i2];
+
+ switch (definition.kind) {
+ case _kinds.Kind.OPERATION_DEFINITION:
+ if (operationName == null) {
+ if (operation !== undefined) {
+ return [new _GraphQLError.GraphQLError('Must provide operation name if query contains multiple operations.')];
+ }
+
+ operation = definition;
+ } else if (((_definition$name = definition.name) === null || _definition$name === void 0 ? void 0 : _definition$name.value) === operationName) {
+ operation = definition;
+ }
+
+ break;
+
+ case _kinds.Kind.FRAGMENT_DEFINITION:
+ fragments[definition.name.value] = definition;
+ break;
+ }
+ }
+
+ if (!operation) {
+ if (operationName != null) {
+ return [new _GraphQLError.GraphQLError("Unknown operation named \"".concat(operationName, "\"."))];
+ }
+
+ return [new _GraphQLError.GraphQLError('Must provide an operation.')];
+ } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+
+
+ var variableDefinitions = (_operation$variableDe = operation.variableDefinitions) !== null && _operation$variableDe !== void 0 ? _operation$variableDe : [];
+ var coercedVariableValues = (0, _values.getVariableValues)(schema, variableDefinitions, rawVariableValues !== null && rawVariableValues !== void 0 ? rawVariableValues : {}, {
+ maxErrors: 50
+ });
+
+ if (coercedVariableValues.errors) {
+ return coercedVariableValues.errors;
+ }
+
+ return {
+ schema: schema,
+ fragments: fragments,
+ rootValue: rootValue,
+ contextValue: contextValue,
+ operation: operation,
+ variableValues: coercedVariableValues.coerced,
+ fieldResolver: fieldResolver !== null && fieldResolver !== void 0 ? fieldResolver : defaultFieldResolver,
+ typeResolver: typeResolver !== null && typeResolver !== void 0 ? typeResolver : defaultTypeResolver,
+ errors: []
+ };
+}
+/**
+ * Implements the "Evaluating operations" section of the spec.
+ */
+
+
+function executeOperation(exeContext, operation, rootValue) {
+ var type = (0, _getOperationRootType.getOperationRootType)(exeContext.schema, operation);
+ var fields = collectFields(exeContext, type, operation.selectionSet, Object.create(null), Object.create(null));
+ var path = undefined; // Errors from sub-fields of a NonNull type may propagate to the top level,
+ // at which point we still log the error and null the parent field, which
+ // in this case is the entire response.
+
+ try {
+ var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
+
+ if ((0, _isPromise.default)(result)) {
+ return result.then(undefined, function (error) {
+ exeContext.errors.push(error);
+ return Promise.resolve(null);
+ });
+ }
+
+ return result;
+ } catch (error) {
+ exeContext.errors.push(error);
+ return null;
+ }
+}
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "write" mode.
+ */
+
+
+function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
+ return (0, _promiseReduce.default)(Object.keys(fields), function (results, responseName) {
+ var fieldNodes = fields[responseName];
+ var fieldPath = (0, _Path.addPath)(path, responseName, parentType.name);
+ var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
+
+ if (result === undefined) {
+ return results;
+ }
+
+ if ((0, _isPromise.default)(result)) {
+ return result.then(function (resolvedResult) {
+ results[responseName] = resolvedResult;
+ return results;
+ });
+ }
+
+ results[responseName] = result;
+ return results;
+ }, Object.create(null));
+}
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "read" mode.
+ */
+
+
+function executeFields(exeContext, parentType, sourceValue, path, fields) {
+ var results = Object.create(null);
+ var containsPromise = false;
+
+ for (var _i4 = 0, _Object$keys2 = Object.keys(fields); _i4 < _Object$keys2.length; _i4++) {
+ var responseName = _Object$keys2[_i4];
+ var fieldNodes = fields[responseName];
+ var fieldPath = (0, _Path.addPath)(path, responseName, parentType.name);
+ var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
+
+ if (result !== undefined) {
+ results[responseName] = result;
+
+ if ((0, _isPromise.default)(result)) {
+ containsPromise = true;
+ }
+ }
+ } // If there are no promises, we can just return the object
+
+
+ if (!containsPromise) {
+ return results;
+ } // Otherwise, results is a map from field name to the result of resolving that
+ // field, which is possibly a promise. Return a promise that will return this
+ // same map, but with any promises replaced with the values they resolved to.
+
+
+ return (0, _promiseForObject.default)(results);
+}
+/**
+ * Given a selectionSet, adds all of the fields in that selection to
+ * the passed in map of fields, and returns it at the end.
+ *
+ * CollectFields requires the "runtime type" of an object. For a field which
+ * returns an Interface or Union type, the "runtime type" will be the actual
+ * Object type returned by that field.
+ *
+ * @internal
+ */
+
+
+function collectFields(exeContext, runtimeType, selectionSet, fields, visitedFragmentNames) {
+ for (var _i6 = 0, _selectionSet$selecti2 = selectionSet.selections; _i6 < _selectionSet$selecti2.length; _i6++) {
+ var selection = _selectionSet$selecti2[_i6];
+
+ switch (selection.kind) {
+ case _kinds.Kind.FIELD:
+ {
+ if (!shouldIncludeNode(exeContext, selection)) {
+ continue;
+ }
+
+ var name = getFieldEntryKey(selection);
+
+ if (!fields[name]) {
+ fields[name] = [];
+ }
+
+ fields[name].push(selection);
+ break;
+ }
+
+ case _kinds.Kind.INLINE_FRAGMENT:
+ {
+ if (!shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(exeContext, selection, runtimeType)) {
+ continue;
+ }
+
+ collectFields(exeContext, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
+ break;
+ }
+
+ case _kinds.Kind.FRAGMENT_SPREAD:
+ {
+ var fragName = selection.name.value;
+
+ if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection)) {
+ continue;
+ }
+
+ visitedFragmentNames[fragName] = true;
+ var fragment = exeContext.fragments[fragName];
+
+ if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
+ continue;
+ }
+
+ collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
+ break;
+ }
+ }
+ }
+
+ return fields;
+}
+/**
+ * Determines if a field should be included based on the @include and @skip
+ * directives, where @skip has higher precedence than @include.
+ */
+
+
+function shouldIncludeNode(exeContext, node) {
+ var skip = (0, _values.getDirectiveValues)(_directives.GraphQLSkipDirective, node, exeContext.variableValues);
+
+ if ((skip === null || skip === void 0 ? void 0 : skip.if) === true) {
+ return false;
+ }
+
+ var include = (0, _values.getDirectiveValues)(_directives.GraphQLIncludeDirective, node, exeContext.variableValues);
+
+ if ((include === null || include === void 0 ? void 0 : include.if) === false) {
+ return false;
+ }
+
+ return true;
+}
+/**
+ * Determines if a fragment is applicable to the given type.
+ */
+
+
+function doesFragmentConditionMatch(exeContext, fragment, type) {
+ var typeConditionNode = fragment.typeCondition;
+
+ if (!typeConditionNode) {
+ return true;
+ }
+
+ var conditionalType = (0, _typeFromAST.typeFromAST)(exeContext.schema, typeConditionNode);
+
+ if (conditionalType === type) {
+ return true;
+ }
+
+ if ((0, _definition.isAbstractType)(conditionalType)) {
+ return exeContext.schema.isSubType(conditionalType, type);
+ }
+
+ return false;
+}
+/**
+ * Implements the logic to compute the key of a given field's entry
+ */
+
+
+function getFieldEntryKey(node) {
+ return node.alias ? node.alias.value : node.name.value;
+}
+/**
+ * Resolves the field on the given source object. In particular, this
+ * figures out the value that the field returns by calling its resolve function,
+ * then calls completeValue to complete promises, serialize scalars, or execute
+ * the sub-selection-set for objects.
+ */
+
+
+function resolveField(exeContext, parentType, source, fieldNodes, path) {
+ var _fieldDef$resolve;
+
+ var fieldNode = fieldNodes[0];
+ var fieldName = fieldNode.name.value;
+ var fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);
+
+ if (!fieldDef) {
+ return;
+ }
+
+ var returnType = fieldDef.type;
+ var resolveFn = (_fieldDef$resolve = fieldDef.resolve) !== null && _fieldDef$resolve !== void 0 ? _fieldDef$resolve : exeContext.fieldResolver;
+ var info = buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path); // Get the resolve function, regardless of if its result is normal or abrupt (error).
+
+ try {
+ // Build a JS object of arguments from the field.arguments AST, using the
+ // variables scope to fulfill any variable references.
+ // TODO: find a way to memoize, in case this field is within a List type.
+ var args = (0, _values.getArgumentValues)(fieldDef, fieldNodes[0], exeContext.variableValues); // The resolve function's optional third argument is a context value that
+ // is provided to every resolve function within an execution. It is commonly
+ // used to represent an authenticated user, or request-specific caches.
+
+ var _contextValue = exeContext.contextValue;
+ var result = resolveFn(source, args, _contextValue, info);
+ var completed;
+
+ if ((0, _isPromise.default)(result)) {
+ completed = result.then(function (resolved) {
+ return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
+ });
+ } else {
+ completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
+ }
+
+ if ((0, _isPromise.default)(completed)) {
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+ return completed.then(undefined, function (rawError) {
+ var error = (0, _locatedError.locatedError)(rawError, fieldNodes, (0, _Path.pathToArray)(path));
+ return handleFieldError(error, returnType, exeContext);
+ });
+ }
+
+ return completed;
+ } catch (rawError) {
+ var error = (0, _locatedError.locatedError)(rawError, fieldNodes, (0, _Path.pathToArray)(path));
+ return handleFieldError(error, returnType, exeContext);
+ }
+}
+/**
+ * @internal
+ */
+
+
+function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
+ // The resolve function's optional fourth argument is a collection of
+ // information about the current execution state.
+ return {
+ fieldName: fieldDef.name,
+ fieldNodes: fieldNodes,
+ returnType: fieldDef.type,
+ parentType: parentType,
+ path: path,
+ schema: exeContext.schema,
+ fragments: exeContext.fragments,
+ rootValue: exeContext.rootValue,
+ operation: exeContext.operation,
+ variableValues: exeContext.variableValues
+ };
+}
+
+function handleFieldError(error, returnType, exeContext) {
+ // If the field type is non-nullable, then it is resolved without any
+ // protection from errors, however it still properly locates the error.
+ if ((0, _definition.isNonNullType)(returnType)) {
+ throw error;
+ } // Otherwise, error protection is applied, logging the error and resolving
+ // a null value for this field if one is encountered.
+
+
+ exeContext.errors.push(error);
+ return null;
+}
+/**
+ * Implements the instructions for completeValue as defined in the
+ * "Field entries" section of the spec.
+ *
+ * If the field type is Non-Null, then this recursively completes the value
+ * for the inner type. It throws a field error if that completion returns null,
+ * as per the "Nullability" section of the spec.
+ *
+ * If the field type is a List, then this recursively completes the value
+ * for the inner type on each item in the list.
+ *
+ * If the field type is a Scalar or Enum, ensures the completed value is a legal
+ * value of the type by calling the `serialize` method of GraphQL type
+ * definition.
+ *
+ * If the field is an abstract type, determine the runtime type of the value
+ * and then complete based on that type
+ *
+ * Otherwise, the field type expects a sub-selection set, and will complete the
+ * value by evaluating all sub-selections.
+ */
+
+
+function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // If result is an Error, throw a located error.
+ if (result instanceof Error) {
+ throw result;
+ } // If field type is NonNull, complete for inner type, and throw field error
+ // if result is null.
+
+
+ if ((0, _definition.isNonNullType)(returnType)) {
+ var completed = completeValue(exeContext, returnType.ofType, fieldNodes, info, path, result);
+
+ if (completed === null) {
+ throw new Error("Cannot return null for non-nullable field ".concat(info.parentType.name, ".").concat(info.fieldName, "."));
+ }
+
+ return completed;
+ } // If result value is null or undefined then return null.
+
+
+ if (result == null) {
+ return null;
+ } // If field type is List, complete each item in the list with the inner type
+
+
+ if ((0, _definition.isListType)(returnType)) {
+ return completeListValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
+ // returning null if serialization is not possible.
+
+
+ if ((0, _definition.isLeafType)(returnType)) {
+ return completeLeafValue(returnType, result);
+ } // If field type is an abstract type, Interface or Union, determine the
+ // runtime Object type and complete for that type.
+
+
+ if ((0, _definition.isAbstractType)(returnType)) {
+ return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // If field type is Object, execute and complete all sub-selections.
+ // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
+
+
+ if ((0, _definition.isObjectType)(returnType)) {
+ return completeObjectValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // istanbul ignore next (Not reachable. All possible output types have been considered)
+
+
+ false || (0, _invariant.default)(0, 'Cannot complete value of unexpected output type: ' + (0, _inspect.default)(returnType));
+}
+/**
+ * Complete a list value by completing each item in the list with the
+ * inner type
+ */
+
+
+function completeListValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // This is specified as a simple map, however we're optimizing the path
+ // where the list contains no Promises by avoiding creating another Promise.
+ var itemType = returnType.ofType;
+ var containsPromise = false;
+ var completedResults = (0, _safeArrayFrom.default)(result, function (item, index) {
+ // No need to modify the info object containing the path,
+ // since from here on it is not ever accessed by resolver functions.
+ var itemPath = (0, _Path.addPath)(path, index, undefined);
+
+ try {
+ var completedItem;
+
+ if ((0, _isPromise.default)(item)) {
+ completedItem = item.then(function (resolved) {
+ return completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved);
+ });
+ } else {
+ completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item);
+ }
+
+ if ((0, _isPromise.default)(completedItem)) {
+ containsPromise = true; // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+
+ return completedItem.then(undefined, function (rawError) {
+ var error = (0, _locatedError.locatedError)(rawError, fieldNodes, (0, _Path.pathToArray)(itemPath));
+ return handleFieldError(error, itemType, exeContext);
+ });
+ }
+
+ return completedItem;
+ } catch (rawError) {
+ var error = (0, _locatedError.locatedError)(rawError, fieldNodes, (0, _Path.pathToArray)(itemPath));
+ return handleFieldError(error, itemType, exeContext);
+ }
+ });
+
+ if (completedResults == null) {
+ throw new _GraphQLError.GraphQLError("Expected Iterable, but did not find one for field \"".concat(info.parentType.name, ".").concat(info.fieldName, "\"."));
+ }
+
+ return containsPromise ? Promise.all(completedResults) : completedResults;
+}
+/**
+ * Complete a Scalar or Enum by serializing to a valid value, returning
+ * null if serialization is not possible.
+ */
+
+
+function completeLeafValue(returnType, result) {
+ var serializedResult = returnType.serialize(result);
+
+ if (serializedResult === undefined) {
+ throw new Error("Expected a value of type \"".concat((0, _inspect.default)(returnType), "\" but ") + "received: ".concat((0, _inspect.default)(result)));
+ }
+
+ return serializedResult;
+}
+/**
+ * Complete a value of an abstract type by determining the runtime object type
+ * of that value, then complete the value for that type.
+ */
+
+
+function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
+ var _returnType$resolveTy;
+
+ var resolveTypeFn = (_returnType$resolveTy = returnType.resolveType) !== null && _returnType$resolveTy !== void 0 ? _returnType$resolveTy : exeContext.typeResolver;
+ var contextValue = exeContext.contextValue;
+ var runtimeType = resolveTypeFn(result, contextValue, info, returnType);
+
+ if ((0, _isPromise.default)(runtimeType)) {
+ return runtimeType.then(function (resolvedRuntimeType) {
+ return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
+ });
+ }
+
+ return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
+}
+
+function ensureValidRuntimeType(runtimeTypeOrName, exeContext, returnType, fieldNodes, info, result) {
+ if (runtimeTypeOrName == null) {
+ throw new _GraphQLError.GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\". Either the \"").concat(returnType.name, "\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."), fieldNodes);
+ } // FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
+
+
+ var runtimeTypeName = (0, _definition.isNamedType)(runtimeTypeOrName) ? runtimeTypeOrName.name : runtimeTypeOrName;
+
+ if (typeof runtimeTypeName !== 'string') {
+ throw new _GraphQLError.GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\" with ") + "value ".concat((0, _inspect.default)(result), ", received \"").concat((0, _inspect.default)(runtimeTypeOrName), "\"."));
+ }
+
+ var runtimeType = exeContext.schema.getType(runtimeTypeName);
+
+ if (runtimeType == null) {
+ throw new _GraphQLError.GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a type \"").concat(runtimeTypeName, "\" that does not exist inside schema."), fieldNodes);
+ }
+
+ if (!(0, _definition.isObjectType)(runtimeType)) {
+ throw new _GraphQLError.GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a non-object type \"").concat(runtimeTypeName, "\"."), fieldNodes);
+ }
+
+ if (!exeContext.schema.isSubType(returnType, runtimeType)) {
+ throw new _GraphQLError.GraphQLError("Runtime Object type \"".concat(runtimeType.name, "\" is not a possible type for \"").concat(returnType.name, "\"."), fieldNodes);
+ }
+
+ return runtimeType;
+}
+/**
+ * Complete an Object value by executing all sub-selections.
+ */
+
+
+function completeObjectValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // If there is an isTypeOf predicate function, call it with the
+ // current result. If isTypeOf returns false, then raise an error rather
+ // than continuing execution.
+ if (returnType.isTypeOf) {
+ var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
+
+ if ((0, _isPromise.default)(isTypeOf)) {
+ return isTypeOf.then(function (resolvedIsTypeOf) {
+ if (!resolvedIsTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+
+ return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result);
+ });
+ }
+
+ if (!isTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+ }
+
+ return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result);
+}
+
+function invalidReturnTypeError(returnType, result, fieldNodes) {
+ return new _GraphQLError.GraphQLError("Expected value of type \"".concat(returnType.name, "\" but got: ").concat((0, _inspect.default)(result), "."), fieldNodes);
+}
+
+function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result) {
+ // Collect sub-fields to execute to complete this value.
+ var subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
+}
+/**
+ * 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.
+ */
+
+
+var collectSubfields = (0, _memoize.default)(_collectSubfields);
+
+function _collectSubfields(exeContext, returnType, fieldNodes) {
+ var subFieldNodes = Object.create(null);
+ var visitedFragmentNames = Object.create(null);
+
+ for (var _i8 = 0; _i8 < fieldNodes.length; _i8++) {
+ var node = fieldNodes[_i8];
+
+ if (node.selectionSet) {
+ subFieldNodes = collectFields(exeContext, returnType, node.selectionSet, subFieldNodes, visitedFragmentNames);
+ }
+ }
+
+ return subFieldNodes;
+}
+/**
+ * If a resolveType function is not given, then a default resolve behavior is
+ * used which attempts two strategies:
+ *
+ * First, See if the provided value has a `__typename` field defined, if so, use
+ * that value as name of the resolved type.
+ *
+ * Otherwise, test each possible type for the abstract type by calling
+ * isTypeOf for the object being coerced, returning the first type that matches.
+ */
+
+
+var defaultTypeResolver = function defaultTypeResolver(value, contextValue, info, abstractType) {
+ // First, look for `__typename`.
+ if ((0, _isObjectLike.default)(value) && typeof value.__typename === 'string') {
+ return value.__typename;
+ } // Otherwise, test each possible type.
+
+
+ var possibleTypes = info.schema.getPossibleTypes(abstractType);
+ var promisedIsTypeOfResults = [];
+
+ for (var i = 0; i < possibleTypes.length; i++) {
+ var type = possibleTypes[i];
+
+ if (type.isTypeOf) {
+ var isTypeOfResult = type.isTypeOf(value, contextValue, info);
+
+ if ((0, _isPromise.default)(isTypeOfResult)) {
+ promisedIsTypeOfResults[i] = isTypeOfResult;
+ } else if (isTypeOfResult) {
+ return type.name;
+ }
+ }
+ }
+
+ if (promisedIsTypeOfResults.length) {
+ return Promise.all(promisedIsTypeOfResults).then(function (isTypeOfResults) {
+ for (var _i9 = 0; _i9 < isTypeOfResults.length; _i9++) {
+ if (isTypeOfResults[_i9]) {
+ return possibleTypes[_i9].name;
+ }
+ }
+ });
+ }
+};
+/**
+ * If a resolve function is not given, then a default resolve behavior is used
+ * which takes the property of the source object of the same name as the field
+ * and returns it as the result, or if it's a function, returns the result
+ * of calling that function while passing along args and context value.
+ */
+
+
+exports.defaultTypeResolver = defaultTypeResolver;
+
+var defaultFieldResolver = function defaultFieldResolver(source, args, contextValue, info) {
+ // ensure source is a value for which property access is acceptable.
+ if ((0, _isObjectLike.default)(source) || typeof source === 'function') {
+ var property = source[info.fieldName];
+
+ if (typeof property === 'function') {
+ return source[info.fieldName](args, contextValue, info);
+ }
+
+ return property;
+ }
+};
+/**
+ * This method looks up the field on the given type definition.
+ * It has special casing for the three introspection fields,
+ * __schema, __type and __typename. __typename is special because
+ * it can always be queried as a field, even in situations where no
+ * other fields are allowed, like on a Union. __schema and __type
+ * could get automatically added to the query type, but that would
+ * require mutating type definitions, which would cause issues.
+ *
+ * @internal
+ */
+
+
+exports.defaultFieldResolver = defaultFieldResolver;
+
+function getFieldDef(schema, parentType, fieldName) {
+ if (fieldName === _introspection.SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {
+ return _introspection.SchemaMetaFieldDef;
+ } else if (fieldName === _introspection.TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
+ return _introspection.TypeMetaFieldDef;
+ } else if (fieldName === _introspection.TypeNameMetaFieldDef.name) {
+ return _introspection.TypeNameMetaFieldDef;
+ }
+
+ return parentType.getFields()[fieldName];
+}
diff --git a/school/node_modules/graphql/execution/execute.js.flow b/school/node_modules/graphql/execution/execute.js.flow
new file mode 100644
index 0000000..604061d
--- /dev/null
+++ b/school/node_modules/graphql/execution/execute.js.flow
@@ -0,0 +1,1246 @@
+// @flow strict
+import type { Path } from '../jsutils/Path';
+import type { ObjMap } from '../jsutils/ObjMap';
+import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
+import inspect from '../jsutils/inspect';
+import memoize3 from '../jsutils/memoize3';
+import invariant from '../jsutils/invariant';
+import devAssert from '../jsutils/devAssert';
+import isPromise from '../jsutils/isPromise';
+import isObjectLike from '../jsutils/isObjectLike';
+import safeArrayFrom from '../jsutils/safeArrayFrom';
+import promiseReduce from '../jsutils/promiseReduce';
+import promiseForObject from '../jsutils/promiseForObject';
+import { addPath, pathToArray } from '../jsutils/Path';
+
+import type { GraphQLFormattedError } from '../error/formatError';
+import { GraphQLError } from '../error/GraphQLError';
+import { locatedError } from '../error/locatedError';
+
+import type {
+ DocumentNode,
+ OperationDefinitionNode,
+ SelectionSetNode,
+ FieldNode,
+ FragmentSpreadNode,
+ InlineFragmentNode,
+ FragmentDefinitionNode,
+} from '../language/ast';
+import { Kind } from '../language/kinds';
+
+import type { GraphQLSchema } from '../type/schema';
+import type {
+ GraphQLObjectType,
+ GraphQLOutputType,
+ GraphQLLeafType,
+ GraphQLAbstractType,
+ GraphQLField,
+ GraphQLFieldResolver,
+ GraphQLResolveInfo,
+ GraphQLTypeResolver,
+ GraphQLList,
+} from '../type/definition';
+import { assertValidSchema } from '../type/validate';
+import {
+ SchemaMetaFieldDef,
+ TypeMetaFieldDef,
+ TypeNameMetaFieldDef,
+} from '../type/introspection';
+import {
+ GraphQLIncludeDirective,
+ GraphQLSkipDirective,
+} from '../type/directives';
+import {
+ isNamedType,
+ isObjectType,
+ isAbstractType,
+ isLeafType,
+ isListType,
+ isNonNullType,
+} from '../type/definition';
+
+import { typeFromAST } from '../utilities/typeFromAST';
+import { getOperationRootType } from '../utilities/getOperationRootType';
+
+import {
+ getVariableValues,
+ getArgumentValues,
+ getDirectiveValues,
+} from './values';
+
+/**
+ * Terminology
+ *
+ * "Definitions" are the generic name for top-level statements in the document.
+ * Examples of this include:
+ * 1) Operations (such as a query)
+ * 2) Fragments
+ *
+ * "Operations" are a generic name for requests in the document.
+ * Examples of this include:
+ * 1) query,
+ * 2) mutation
+ *
+ * "Selections" are the definitions that can appear legally and at
+ * single level of the query. These include:
+ * 1) field references e.g "a"
+ * 2) fragment "spreads" e.g. "...c"
+ * 3) inline fragment "spreads" e.g. "...on Type { a }"
+ */
+
+/**
+ * Data that must be available at all points during query execution.
+ *
+ * Namely, schema of the type system that is currently executing,
+ * and the fragments defined in the query document
+ */
+export type ExecutionContext = {|
+ schema: GraphQLSchema,
+ fragments: ObjMap<FragmentDefinitionNode>,
+ rootValue: mixed,
+ contextValue: mixed,
+ operation: OperationDefinitionNode,
+ variableValues: { [variable: string]: mixed, ... },
+ fieldResolver: GraphQLFieldResolver<any, any>,
+ typeResolver: GraphQLTypeResolver<any, any>,
+ errors: Array<GraphQLError>,
+|};
+
+/**
+ * The result of GraphQL execution.
+ *
+ * - `errors` is included when any errors occurred as a non-empty array.
+ * - `data` is the result of a successful execution of the query.
+ * - `extensions` is reserved for adding non-standard properties.
+ */
+export type ExecutionResult = {|
+ errors?: $ReadOnlyArray<GraphQLError>,
+ data?: ObjMap<mixed> | null,
+ extensions?: ObjMap<mixed>,
+|};
+
+export type FormattedExecutionResult = {|
+ errors?: $ReadOnlyArray<GraphQLFormattedError>,
+ data?: ObjMap<mixed> | null,
+ extensions?: ObjMap<mixed>,
+|};
+
+export type ExecutionArgs = {|
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rootValue?: mixed,
+ contextValue?: mixed,
+ variableValues?: ?{ +[variable: string]: mixed, ... },
+ operationName?: ?string,
+ fieldResolver?: ?GraphQLFieldResolver<any, any>,
+ typeResolver?: ?GraphQLTypeResolver<any, any>,
+|};
+
+/**
+ * Implements the "Evaluating requests" section of the GraphQL specification.
+ *
+ * Returns either a synchronous ExecutionResult (if all encountered resolvers
+ * are synchronous), or a Promise of an ExecutionResult that will eventually be
+ * resolved and never rejected.
+ *
+ * If the arguments to this function do not result in a legal execution context,
+ * a GraphQLError will be thrown immediately explaining the invalid input.
+ *
+ * Accepts either an object with named arguments, or individual arguments.
+ */
+declare function execute(
+ ExecutionArgs,
+ ..._: []
+): PromiseOrValue<ExecutionResult>;
+/* eslint-disable no-redeclare */
+declare function execute(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rootValue?: mixed,
+ contextValue?: mixed,
+ variableValues?: ?{ +[variable: string]: mixed, ... },
+ operationName?: ?string,
+ fieldResolver?: ?GraphQLFieldResolver<any, any>,
+ typeResolver?: ?GraphQLTypeResolver<any, any>,
+): PromiseOrValue<ExecutionResult>;
+export function execute(
+ argsOrSchema,
+ document,
+ rootValue,
+ contextValue,
+ variableValues,
+ operationName,
+ fieldResolver,
+ typeResolver,
+) {
+ /* eslint-enable no-redeclare */
+ // Extract arguments from object args if provided.
+ return arguments.length === 1
+ ? executeImpl(argsOrSchema)
+ : executeImpl({
+ schema: argsOrSchema,
+ document,
+ rootValue,
+ contextValue,
+ variableValues,
+ operationName,
+ fieldResolver,
+ typeResolver,
+ });
+}
+
+/**
+ * Also implements the "Evaluating requests" section of the GraphQL specification.
+ * However, it guarantees to complete synchronously (or throw an error) assuming
+ * that all field resolvers are also synchronous.
+ */
+export function executeSync(args: ExecutionArgs): ExecutionResult {
+ const result = executeImpl(args);
+
+ // Assert that the execution was synchronous.
+ if (isPromise(result)) {
+ throw new Error('GraphQL execution failed to complete synchronously.');
+ }
+
+ return result;
+}
+
+function executeImpl(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
+ const {
+ schema,
+ document,
+ rootValue,
+ contextValue,
+ variableValues,
+ operationName,
+ fieldResolver,
+ typeResolver,
+ } = args;
+
+ // If arguments are missing or incorrect, throw an error.
+ assertValidExecutionArguments(schema, document, variableValues);
+
+ // If a valid execution context cannot be created due to incorrect arguments,
+ // a "Response" with only errors is returned.
+ const exeContext = buildExecutionContext(
+ schema,
+ document,
+ rootValue,
+ contextValue,
+ variableValues,
+ operationName,
+ fieldResolver,
+ typeResolver,
+ );
+
+ // Return early errors if execution context failed.
+ if (Array.isArray(exeContext)) {
+ return { errors: exeContext };
+ }
+
+ // Return a Promise that will eventually resolve to the data described by
+ // The "Response" section of the GraphQL specification.
+ //
+ // If errors are encountered while executing a GraphQL field, only that
+ // field and its descendants will be omitted, and sibling fields will still
+ // be executed. An execution which encounters errors will still result in a
+ // resolved Promise.
+ const data = executeOperation(exeContext, exeContext.operation, rootValue);
+ return buildResponse(exeContext, data);
+}
+
+/**
+ * Given a completed execution context and data, build the { errors, data }
+ * response defined by the "Response" section of the GraphQL specification.
+ */
+function buildResponse(
+ exeContext: ExecutionContext,
+ data: PromiseOrValue<ObjMap<mixed> | null>,
+): PromiseOrValue<ExecutionResult> {
+ if (isPromise(data)) {
+ return data.then((resolved) => buildResponse(exeContext, resolved));
+ }
+ return exeContext.errors.length === 0
+ ? { data }
+ : { errors: exeContext.errors, data };
+}
+
+/**
+ * Essential assertions before executing to provide developer feedback for
+ * improper use of the GraphQL library.
+ *
+ * @internal
+ */
+export function assertValidExecutionArguments(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rawVariableValues: ?{ +[variable: string]: mixed, ... },
+): void {
+ devAssert(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.',
+ );
+}
+
+/**
+ * Constructs a ExecutionContext object from the arguments passed to
+ * execute, which we will pass throughout the other execution methods.
+ *
+ * Throws a GraphQLError if a valid execution context cannot be created.
+ *
+ * @internal
+ */
+export function buildExecutionContext(
+ schema: GraphQLSchema,
+ document: DocumentNode,
+ rootValue: mixed,
+ contextValue: mixed,
+ rawVariableValues: ?{ +[variable: string]: mixed, ... },
+ operationName: ?string,
+ fieldResolver: ?GraphQLFieldResolver<mixed, mixed>,
+ typeResolver?: ?GraphQLTypeResolver<mixed, mixed>,
+): $ReadOnlyArray<GraphQLError> | ExecutionContext {
+ let operation: OperationDefinitionNode | void;
+ const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null);
+ for (const definition of document.definitions) {
+ switch (definition.kind) {
+ case Kind.OPERATION_DEFINITION:
+ if (operationName == null) {
+ if (operation !== undefined) {
+ return [
+ new GraphQLError(
+ 'Must provide operation name if query contains multiple operations.',
+ ),
+ ];
+ }
+ operation = definition;
+ } else if (definition.name?.value === operationName) {
+ operation = definition;
+ }
+ break;
+ case Kind.FRAGMENT_DEFINITION:
+ fragments[definition.name.value] = definition;
+ break;
+ }
+ }
+
+ if (!operation) {
+ if (operationName != null) {
+ return [new GraphQLError(`Unknown operation named "${operationName}".`)];
+ }
+ return [new GraphQLError('Must provide an operation.')];
+ }
+
+ // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+ const variableDefinitions = operation.variableDefinitions ?? [];
+
+ const coercedVariableValues = getVariableValues(
+ schema,
+ variableDefinitions,
+ rawVariableValues ?? {},
+ { maxErrors: 50 },
+ );
+
+ if (coercedVariableValues.errors) {
+ return coercedVariableValues.errors;
+ }
+
+ return {
+ schema,
+ fragments,
+ rootValue,
+ contextValue,
+ operation,
+ variableValues: coercedVariableValues.coerced,
+ fieldResolver: fieldResolver ?? defaultFieldResolver,
+ typeResolver: typeResolver ?? defaultTypeResolver,
+ errors: [],
+ };
+}
+
+/**
+ * Implements the "Evaluating operations" section of the spec.
+ */
+function executeOperation(
+ exeContext: ExecutionContext,
+ operation: OperationDefinitionNode,
+ rootValue: mixed,
+): PromiseOrValue<ObjMap<mixed> | null> {
+ const type = getOperationRootType(exeContext.schema, operation);
+ const fields = collectFields(
+ exeContext,
+ type,
+ operation.selectionSet,
+ Object.create(null),
+ Object.create(null),
+ );
+
+ const path = undefined;
+
+ // Errors from sub-fields of a NonNull type may propagate to the top level,
+ // at which point we still log the error and null the parent field, which
+ // in this case is the entire response.
+ try {
+ const result =
+ operation.operation === 'mutation'
+ ? executeFieldsSerially(exeContext, type, rootValue, path, fields)
+ : executeFields(exeContext, type, rootValue, path, fields);
+ if (isPromise(result)) {
+ return result.then(undefined, (error) => {
+ exeContext.errors.push(error);
+ return Promise.resolve(null);
+ });
+ }
+ return result;
+ } catch (error) {
+ exeContext.errors.push(error);
+ return null;
+ }
+}
+
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "write" mode.
+ */
+function executeFieldsSerially(
+ exeContext: ExecutionContext,
+ parentType: GraphQLObjectType,
+ sourceValue: mixed,
+ path: Path | void,
+ fields: ObjMap<Array<FieldNode>>,
+): PromiseOrValue<ObjMap<mixed>> {
+ return promiseReduce(
+ Object.keys(fields),
+ (results, responseName) => {
+ const fieldNodes = fields[responseName];
+ const fieldPath = addPath(path, responseName, parentType.name);
+ const result = resolveField(
+ exeContext,
+ parentType,
+ sourceValue,
+ fieldNodes,
+ fieldPath,
+ );
+ if (result === undefined) {
+ return results;
+ }
+ if (isPromise(result)) {
+ return result.then((resolvedResult) => {
+ results[responseName] = resolvedResult;
+ return results;
+ });
+ }
+ results[responseName] = result;
+ return results;
+ },
+ Object.create(null),
+ );
+}
+
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "read" mode.
+ */
+function executeFields(
+ exeContext: ExecutionContext,
+ parentType: GraphQLObjectType,
+ sourceValue: mixed,
+ path: Path | void,
+ fields: ObjMap<Array<FieldNode>>,
+): PromiseOrValue<ObjMap<mixed>> {
+ const results = Object.create(null);
+ let containsPromise = false;
+
+ for (const responseName of Object.keys(fields)) {
+ const fieldNodes = fields[responseName];
+ const fieldPath = addPath(path, responseName, parentType.name);
+ const result = resolveField(
+ exeContext,
+ parentType,
+ sourceValue,
+ fieldNodes,
+ fieldPath,
+ );
+
+ if (result !== undefined) {
+ results[responseName] = result;
+ if (isPromise(result)) {
+ containsPromise = true;
+ }
+ }
+ }
+
+ // If there are no promises, we can just return the object
+ if (!containsPromise) {
+ return results;
+ }
+
+ // Otherwise, results is a map from field name to the result of resolving that
+ // field, which is possibly a promise. Return a promise that will return this
+ // same map, but with any promises replaced with the values they resolved to.
+ return promiseForObject(results);
+}
+
+/**
+ * Given a selectionSet, adds all of the fields in that selection to
+ * the passed in map of fields, and returns it at the end.
+ *
+ * CollectFields requires the "runtime type" of an object. For a field which
+ * returns an Interface or Union type, the "runtime type" will be the actual
+ * Object type returned by that field.
+ *
+ * @internal
+ */
+export function collectFields(
+ exeContext: ExecutionContext,
+ runtimeType: GraphQLObjectType,
+ selectionSet: SelectionSetNode,
+ fields: ObjMap<Array<FieldNode>>,
+ visitedFragmentNames: ObjMap<boolean>,
+): ObjMap<Array<FieldNode>> {
+ for (const selection of selectionSet.selections) {
+ switch (selection.kind) {
+ case Kind.FIELD: {
+ if (!shouldIncludeNode(exeContext, selection)) {
+ continue;
+ }
+ const name = getFieldEntryKey(selection);
+ if (!fields[name]) {
+ fields[name] = [];
+ }
+ fields[name].push(selection);
+ break;
+ }
+ case Kind.INLINE_FRAGMENT: {
+ if (
+ !shouldIncludeNode(exeContext, selection) ||
+ !doesFragmentConditionMatch(exeContext, selection, runtimeType)
+ ) {
+ continue;
+ }
+ collectFields(
+ exeContext,
+ runtimeType,
+ selection.selectionSet,
+ fields,
+ visitedFragmentNames,
+ );
+ break;
+ }
+ case Kind.FRAGMENT_SPREAD: {
+ const fragName = selection.name.value;
+ if (
+ visitedFragmentNames[fragName] ||
+ !shouldIncludeNode(exeContext, selection)
+ ) {
+ continue;
+ }
+ visitedFragmentNames[fragName] = true;
+ const fragment = exeContext.fragments[fragName];
+ if (
+ !fragment ||
+ !doesFragmentConditionMatch(exeContext, fragment, runtimeType)
+ ) {
+ continue;
+ }
+ collectFields(
+ exeContext,
+ runtimeType,
+ fragment.selectionSet,
+ fields,
+ visitedFragmentNames,
+ );
+ break;
+ }
+ }
+ }
+ return fields;
+}
+
+/**
+ * Determines if a field should be included based on the @include and @skip
+ * directives, where @skip has higher precedence than @include.
+ */
+function shouldIncludeNode(
+ exeContext: ExecutionContext,
+ node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
+): boolean {
+ const skip = getDirectiveValues(
+ GraphQLSkipDirective,
+ node,
+ exeContext.variableValues,
+ );
+ if (skip?.if === true) {
+ return false;
+ }
+
+ const include = getDirectiveValues(
+ GraphQLIncludeDirective,
+ node,
+ exeContext.variableValues,
+ );
+ if (include?.if === false) {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Determines if a fragment is applicable to the given type.
+ */
+function doesFragmentConditionMatch(
+ exeContext: ExecutionContext,
+ fragment: FragmentDefinitionNode | InlineFragmentNode,
+ type: GraphQLObjectType,
+): boolean {
+ const typeConditionNode = fragment.typeCondition;
+ if (!typeConditionNode) {
+ return true;
+ }
+ const conditionalType = typeFromAST(exeContext.schema, typeConditionNode);
+ if (conditionalType === type) {
+ return true;
+ }
+ if (isAbstractType(conditionalType)) {
+ return exeContext.schema.isSubType(conditionalType, type);
+ }
+ return false;
+}
+
+/**
+ * Implements the logic to compute the key of a given field's entry
+ */
+function getFieldEntryKey(node: FieldNode): string {
+ return node.alias ? node.alias.value : node.name.value;
+}
+
+/**
+ * Resolves the field on the given source object. In particular, this
+ * figures out the value that the field returns by calling its resolve function,
+ * then calls completeValue to complete promises, serialize scalars, or execute
+ * the sub-selection-set for objects.
+ */
+function resolveField(
+ exeContext: ExecutionContext,
+ parentType: GraphQLObjectType,
+ source: mixed,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ path: Path,
+): PromiseOrValue<mixed> {
+ const fieldNode = fieldNodes[0];
+ const fieldName = fieldNode.name.value;
+
+ const fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);
+ if (!fieldDef) {
+ return;
+ }
+
+ const returnType = fieldDef.type;
+ const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver;
+
+ const info = buildResolveInfo(
+ exeContext,
+ fieldDef,
+ fieldNodes,
+ parentType,
+ path,
+ );
+
+ // Get the resolve function, regardless of if its result is normal or abrupt (error).
+ try {
+ // Build a JS object of arguments from the field.arguments AST, using the
+ // variables scope to fulfill any variable references.
+ // TODO: find a way to memoize, in case this field is within a List type.
+ const args = getArgumentValues(
+ fieldDef,
+ fieldNodes[0],
+ exeContext.variableValues,
+ );
+
+ // The resolve function's optional third argument is a context value that
+ // is provided to every resolve function within an execution. It is commonly
+ // used to represent an authenticated user, or request-specific caches.
+ const contextValue = exeContext.contextValue;
+
+ const result = resolveFn(source, args, contextValue, info);
+
+ let completed;
+ if (isPromise(result)) {
+ completed = result.then((resolved) =>
+ completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
+ );
+ } else {
+ completed = completeValue(
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+ }
+
+ if (isPromise(completed)) {
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+ return completed.then(undefined, (rawError) => {
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
+ return handleFieldError(error, returnType, exeContext);
+ });
+ }
+ return completed;
+ } catch (rawError) {
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
+ return handleFieldError(error, returnType, exeContext);
+ }
+}
+
+/**
+ * @internal
+ */
+export function buildResolveInfo(
+ exeContext: ExecutionContext,
+ fieldDef: GraphQLField<mixed, mixed>,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ parentType: GraphQLObjectType,
+ path: Path,
+): GraphQLResolveInfo {
+ // The resolve function's optional fourth argument is a collection of
+ // information about the current execution state.
+ return {
+ fieldName: fieldDef.name,
+ fieldNodes,
+ returnType: fieldDef.type,
+ parentType,
+ path,
+ schema: exeContext.schema,
+ fragments: exeContext.fragments,
+ rootValue: exeContext.rootValue,
+ operation: exeContext.operation,
+ variableValues: exeContext.variableValues,
+ };
+}
+
+function handleFieldError(
+ error: GraphQLError,
+ returnType: GraphQLOutputType,
+ exeContext: ExecutionContext,
+): null {
+ // If the field type is non-nullable, then it is resolved without any
+ // protection from errors, however it still properly locates the error.
+ if (isNonNullType(returnType)) {
+ throw error;
+ }
+
+ // Otherwise, error protection is applied, logging the error and resolving
+ // a null value for this field if one is encountered.
+ exeContext.errors.push(error);
+ return null;
+}
+
+/**
+ * Implements the instructions for completeValue as defined in the
+ * "Field entries" section of the spec.
+ *
+ * If the field type is Non-Null, then this recursively completes the value
+ * for the inner type. It throws a field error if that completion returns null,
+ * as per the "Nullability" section of the spec.
+ *
+ * If the field type is a List, then this recursively completes the value
+ * for the inner type on each item in the list.
+ *
+ * If the field type is a Scalar or Enum, ensures the completed value is a legal
+ * value of the type by calling the `serialize` method of GraphQL type
+ * definition.
+ *
+ * If the field is an abstract type, determine the runtime type of the value
+ * and then complete based on that type
+ *
+ * Otherwise, the field type expects a sub-selection set, and will complete the
+ * value by evaluating all sub-selections.
+ */
+function completeValue(
+ exeContext: ExecutionContext,
+ returnType: GraphQLOutputType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ info: GraphQLResolveInfo,
+ path: Path,
+ result: mixed,
+): PromiseOrValue<mixed> {
+ // If result is an Error, throw a located error.
+ if (result instanceof Error) {
+ throw result;
+ }
+
+ // If field type is NonNull, complete for inner type, and throw field error
+ // if result is null.
+ if (isNonNullType(returnType)) {
+ const completed = completeValue(
+ exeContext,
+ returnType.ofType,
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+ if (completed === null) {
+ throw new Error(
+ `Cannot return null for non-nullable field ${info.parentType.name}.${info.fieldName}.`,
+ );
+ }
+ return completed;
+ }
+
+ // If result value is null or undefined then return null.
+ if (result == null) {
+ return null;
+ }
+
+ // If field type is List, complete each item in the list with the inner type
+ if (isListType(returnType)) {
+ return completeListValue(
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+ }
+
+ // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
+ // returning null if serialization is not possible.
+ if (isLeafType(returnType)) {
+ return completeLeafValue(returnType, result);
+ }
+
+ // If field type is an abstract type, Interface or Union, determine the
+ // runtime Object type and complete for that type.
+ if (isAbstractType(returnType)) {
+ return completeAbstractValue(
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+ }
+
+ // If field type is Object, execute and complete all sub-selections.
+ // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
+ if (isObjectType(returnType)) {
+ return completeObjectValue(
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+ }
+
+ // istanbul ignore next (Not reachable. All possible output types have been considered)
+ invariant(
+ false,
+ 'Cannot complete value of unexpected output type: ' +
+ inspect((returnType: empty)),
+ );
+}
+
+/**
+ * Complete a list value by completing each item in the list with the
+ * inner type
+ */
+function completeListValue(
+ exeContext: ExecutionContext,
+ returnType: GraphQLList<GraphQLOutputType>,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ info: GraphQLResolveInfo,
+ path: Path,
+ result: mixed,
+): PromiseOrValue<$ReadOnlyArray<mixed>> {
+ // This is specified as a simple map, however we're optimizing the path
+ // where the list contains no Promises by avoiding creating another Promise.
+ const itemType = returnType.ofType;
+ let containsPromise = false;
+ const completedResults = safeArrayFrom(result, (item, index) => {
+ // No need to modify the info object containing the path,
+ // since from here on it is not ever accessed by resolver functions.
+ const itemPath = addPath(path, index, undefined);
+ try {
+ let completedItem;
+ if (isPromise(item)) {
+ completedItem = item.then((resolved) =>
+ completeValue(
+ exeContext,
+ itemType,
+ fieldNodes,
+ info,
+ itemPath,
+ resolved,
+ ),
+ );
+ } else {
+ completedItem = completeValue(
+ exeContext,
+ itemType,
+ fieldNodes,
+ info,
+ itemPath,
+ item,
+ );
+ }
+
+ if (isPromise(completedItem)) {
+ containsPromise = true;
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+ return completedItem.then(undefined, (rawError) => {
+ const error = locatedError(
+ rawError,
+ fieldNodes,
+ pathToArray(itemPath),
+ );
+ return handleFieldError(error, itemType, exeContext);
+ });
+ }
+ return completedItem;
+ } catch (rawError) {
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
+ return handleFieldError(error, itemType, exeContext);
+ }
+ });
+
+ if (completedResults == null) {
+ throw new GraphQLError(
+ `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
+ );
+ }
+
+ return containsPromise ? Promise.all(completedResults) : completedResults;
+}
+
+/**
+ * Complete a Scalar or Enum by serializing to a valid value, returning
+ * null if serialization is not possible.
+ */
+function completeLeafValue(returnType: GraphQLLeafType, result: mixed): mixed {
+ const serializedResult = returnType.serialize(result);
+ if (serializedResult === undefined) {
+ throw new Error(
+ `Expected a value of type "${inspect(returnType)}" but ` +
+ `received: ${inspect(result)}`,
+ );
+ }
+ return serializedResult;
+}
+
+/**
+ * Complete a value of an abstract type by determining the runtime object type
+ * of that value, then complete the value for that type.
+ */
+function completeAbstractValue(
+ exeContext: ExecutionContext,
+ returnType: GraphQLAbstractType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ info: GraphQLResolveInfo,
+ path: Path,
+ result: mixed,
+): PromiseOrValue<ObjMap<mixed>> {
+ const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver;
+ const contextValue = exeContext.contextValue;
+ const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
+
+ if (isPromise(runtimeType)) {
+ return runtimeType.then((resolvedRuntimeType) =>
+ completeObjectValue(
+ exeContext,
+ ensureValidRuntimeType(
+ resolvedRuntimeType,
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ result,
+ ),
+ fieldNodes,
+ info,
+ path,
+ result,
+ ),
+ );
+ }
+
+ return completeObjectValue(
+ exeContext,
+ ensureValidRuntimeType(
+ runtimeType,
+ exeContext,
+ returnType,
+ fieldNodes,
+ info,
+ result,
+ ),
+ fieldNodes,
+ info,
+ path,
+ result,
+ );
+}
+
+function ensureValidRuntimeType(
+ runtimeTypeOrName: mixed,
+ exeContext: ExecutionContext,
+ returnType: GraphQLAbstractType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ info: GraphQLResolveInfo,
+ result: mixed,
+): GraphQLObjectType {
+ if (runtimeTypeOrName == 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.`,
+ fieldNodes,
+ );
+ }
+
+ // FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
+ const runtimeTypeName = isNamedType(runtimeTypeOrName)
+ ? runtimeTypeOrName.name
+ : runtimeTypeOrName;
+
+ 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 ` +
+ `value ${inspect(result)}, received "${inspect(runtimeTypeOrName)}".`,
+ );
+ }
+
+ const runtimeType = exeContext.schema.getType(runtimeTypeName);
+ if (runtimeType == null) {
+ throw new GraphQLError(
+ `Abstract type "${returnType.name}" was resolve to a type "${runtimeTypeName}" that does not exist inside schema.`,
+ fieldNodes,
+ );
+ }
+
+ if (!isObjectType(runtimeType)) {
+ throw new GraphQLError(
+ `Abstract type "${returnType.name}" was resolve to a non-object type "${runtimeTypeName}".`,
+ fieldNodes,
+ );
+ }
+
+ if (!exeContext.schema.isSubType(returnType, runtimeType)) {
+ throw new GraphQLError(
+ `Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`,
+ fieldNodes,
+ );
+ }
+
+ return runtimeType;
+}
+
+/**
+ * Complete an Object value by executing all sub-selections.
+ */
+function completeObjectValue(
+ exeContext: ExecutionContext,
+ returnType: GraphQLObjectType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ info: GraphQLResolveInfo,
+ path: Path,
+ result: mixed,
+): PromiseOrValue<ObjMap<mixed>> {
+ // If there is an isTypeOf predicate function, call it with the
+ // current result. If isTypeOf returns false, then raise an error rather
+ // than continuing execution.
+ if (returnType.isTypeOf) {
+ const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
+
+ if (isPromise(isTypeOf)) {
+ return isTypeOf.then((resolvedIsTypeOf) => {
+ if (!resolvedIsTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+ return collectAndExecuteSubfields(
+ exeContext,
+ returnType,
+ fieldNodes,
+ path,
+ result,
+ );
+ });
+ }
+
+ if (!isTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+ }
+
+ return collectAndExecuteSubfields(
+ exeContext,
+ returnType,
+ fieldNodes,
+ path,
+ result,
+ );
+}
+
+function invalidReturnTypeError(
+ returnType: GraphQLObjectType,
+ result: mixed,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+): GraphQLError {
+ return new GraphQLError(
+ `Expected value of type "${returnType.name}" but got: ${inspect(result)}.`,
+ fieldNodes,
+ );
+}
+
+function collectAndExecuteSubfields(
+ exeContext: ExecutionContext,
+ returnType: GraphQLObjectType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+ path: Path,
+ result: mixed,
+): PromiseOrValue<ObjMap<mixed>> {
+ // Collect sub-fields to execute to complete this value.
+ const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
+}
+
+/**
+ * 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(_collectSubfields);
+function _collectSubfields(
+ exeContext: ExecutionContext,
+ returnType: GraphQLObjectType,
+ fieldNodes: $ReadOnlyArray<FieldNode>,
+): ObjMap<Array<FieldNode>> {
+ let subFieldNodes = Object.create(null);
+ const visitedFragmentNames = Object.create(null);
+ for (const node of fieldNodes) {
+ if (node.selectionSet) {
+ subFieldNodes = collectFields(
+ exeContext,
+ returnType,
+ node.selectionSet,
+ subFieldNodes,
+ visitedFragmentNames,
+ );
+ }
+ }
+ return subFieldNodes;
+}
+
+/**
+ * If a resolveType function is not given, then a default resolve behavior is
+ * used which attempts two strategies:
+ *
+ * First, See if the provided value has a `__typename` field defined, if so, use
+ * that value as name of the resolved type.
+ *
+ * Otherwise, test each possible type for the abstract type by calling
+ * isTypeOf for the object being coerced, returning the first type that matches.
+ */
+export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
+ value,
+ contextValue,
+ info,
+ abstractType,
+) {
+ // First, look for `__typename`.
+ if (isObjectLike(value) && typeof value.__typename === 'string') {
+ return value.__typename;
+ }
+
+ // Otherwise, test each possible type.
+ const possibleTypes = info.schema.getPossibleTypes(abstractType);
+ const promisedIsTypeOfResults = [];
+
+ for (let i = 0; i < possibleTypes.length; i++) {
+ const type = possibleTypes[i];
+
+ if (type.isTypeOf) {
+ const isTypeOfResult = type.isTypeOf(value, contextValue, info);
+
+ if (isPromise(isTypeOfResult)) {
+ promisedIsTypeOfResults[i] = isTypeOfResult;
+ } else if (isTypeOfResult) {
+ return type.name;
+ }
+ }
+ }
+
+ if (promisedIsTypeOfResults.length) {
+ return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
+ for (let i = 0; i < isTypeOfResults.length; i++) {
+ if (isTypeOfResults[i]) {
+ return possibleTypes[i].name;
+ }
+ }
+ });
+ }
+};
+
+/**
+ * If a resolve function is not given, then a default resolve behavior is used
+ * which takes the property of the source object of the same name as the field
+ * and returns it as the result, or if it's a function, returns the result
+ * of calling that function while passing along args and context value.
+ */
+export const defaultFieldResolver: GraphQLFieldResolver<
+ mixed,
+ mixed,
+> = function (source: any, args, contextValue, info) {
+ // ensure source is a value for which property access is acceptable.
+ if (isObjectLike(source) || typeof source === 'function') {
+ const property = source[info.fieldName];
+ if (typeof property === 'function') {
+ return source[info.fieldName](args, contextValue, info);
+ }
+ return property;
+ }
+};
+
+/**
+ * This method looks up the field on the given type definition.
+ * It has special casing for the three introspection fields,
+ * __schema, __type and __typename. __typename is special because
+ * it can always be queried as a field, even in situations where no
+ * other fields are allowed, like on a Union. __schema and __type
+ * could get automatically added to the query type, but that would
+ * require mutating type definitions, which would cause issues.
+ *
+ * @internal
+ */
+export function getFieldDef(
+ schema: GraphQLSchema,
+ parentType: GraphQLObjectType,
+ fieldName: string,
+): ?GraphQLField<mixed, mixed> {
+ if (
+ fieldName === SchemaMetaFieldDef.name &&
+ schema.getQueryType() === parentType
+ ) {
+ return SchemaMetaFieldDef;
+ } else if (
+ fieldName === TypeMetaFieldDef.name &&
+ schema.getQueryType() === parentType
+ ) {
+ return TypeMetaFieldDef;
+ } else if (fieldName === TypeNameMetaFieldDef.name) {
+ return TypeNameMetaFieldDef;
+ }
+ return parentType.getFields()[fieldName];
+}
diff --git a/school/node_modules/graphql/execution/execute.mjs b/school/node_modules/graphql/execution/execute.mjs
new file mode 100644
index 0000000..9cf5b92
--- /dev/null
+++ b/school/node_modules/graphql/execution/execute.mjs
@@ -0,0 +1,847 @@
+import inspect from "../jsutils/inspect.mjs";
+import memoize3 from "../jsutils/memoize3.mjs";
+import invariant from "../jsutils/invariant.mjs";
+import devAssert from "../jsutils/devAssert.mjs";
+import isPromise from "../jsutils/isPromise.mjs";
+import isObjectLike from "../jsutils/isObjectLike.mjs";
+import safeArrayFrom from "../jsutils/safeArrayFrom.mjs";
+import promiseReduce from "../jsutils/promiseReduce.mjs";
+import promiseForObject from "../jsutils/promiseForObject.mjs";
+import { addPath, pathToArray } from "../jsutils/Path.mjs";
+import { GraphQLError } from "../error/GraphQLError.mjs";
+import { locatedError } from "../error/locatedError.mjs";
+import { Kind } from "../language/kinds.mjs";
+import { assertValidSchema } from "../type/validate.mjs";
+import { SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef } from "../type/introspection.mjs";
+import { GraphQLIncludeDirective, GraphQLSkipDirective } from "../type/directives.mjs";
+import { isNamedType, isObjectType, isAbstractType, isLeafType, isListType, isNonNullType } from "../type/definition.mjs";
+import { typeFromAST } from "../utilities/typeFromAST.mjs";
+import { getOperationRootType } from "../utilities/getOperationRootType.mjs";
+import { getVariableValues, getArgumentValues, getDirectiveValues } from "./values.mjs";
+/**
+ * Terminology
+ *
+ * "Definitions" are the generic name for top-level statements in the document.
+ * Examples of this include:
+ * 1) Operations (such as a query)
+ * 2) Fragments
+ *
+ * "Operations" are a generic name for requests in the document.
+ * Examples of this include:
+ * 1) query,
+ * 2) mutation
+ *
+ * "Selections" are the definitions that can appear legally and at
+ * single level of the query. These include:
+ * 1) field references e.g "a"
+ * 2) fragment "spreads" e.g. "...c"
+ * 3) inline fragment "spreads" e.g. "...on Type { a }"
+ */
+
+/**
+ * Data that must be available at all points during query execution.
+ *
+ * Namely, schema of the type system that is currently executing,
+ * and the fragments defined in the query document
+ */
+
+export function execute(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
+ /* eslint-enable no-redeclare */
+ // Extract arguments from object args if provided.
+ return arguments.length === 1 ? executeImpl(argsOrSchema) : executeImpl({
+ schema: argsOrSchema,
+ document: document,
+ rootValue: rootValue,
+ contextValue: contextValue,
+ variableValues: variableValues,
+ operationName: operationName,
+ fieldResolver: fieldResolver,
+ typeResolver: typeResolver
+ });
+}
+/**
+ * Also implements the "Evaluating requests" section of the GraphQL specification.
+ * However, it guarantees to complete synchronously (or throw an error) assuming
+ * that all field resolvers are also synchronous.
+ */
+
+export function executeSync(args) {
+ var result = executeImpl(args); // Assert that the execution was synchronous.
+
+ if (isPromise(result)) {
+ throw new Error('GraphQL execution failed to complete synchronously.');
+ }
+
+ return result;
+}
+
+function executeImpl(args) {
+ var schema = args.schema,
+ document = args.document,
+ rootValue = args.rootValue,
+ contextValue = args.contextValue,
+ variableValues = args.variableValues,
+ operationName = args.operationName,
+ fieldResolver = args.fieldResolver,
+ typeResolver = args.typeResolver; // If arguments are missing or incorrect, throw an error.
+
+ assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
+ // a "Response" with only errors is returned.
+
+ var exeContext = buildExecutionContext(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver); // Return early errors if execution context failed.
+
+ if (Array.isArray(exeContext)) {
+ return {
+ errors: exeContext
+ };
+ } // Return a Promise that will eventually resolve to the data described by
+ // The "Response" section of the GraphQL specification.
+ //
+ // If errors are encountered while executing a GraphQL field, only that
+ // field and its descendants will be omitted, and sibling fields will still
+ // be executed. An execution which encounters errors will still result in a
+ // resolved Promise.
+
+
+ var data = executeOperation(exeContext, exeContext.operation, rootValue);
+ return buildResponse(exeContext, data);
+}
+/**
+ * Given a completed execution context and data, build the { errors, data }
+ * response defined by the "Response" section of the GraphQL specification.
+ */
+
+
+function buildResponse(exeContext, data) {
+ if (isPromise(data)) {
+ return data.then(function (resolved) {
+ return buildResponse(exeContext, resolved);
+ });
+ }
+
+ return exeContext.errors.length === 0 ? {
+ data: data
+ } : {
+ errors: exeContext.errors,
+ data: data
+ };
+}
+/**
+ * Essential assertions before executing to provide developer feedback for
+ * improper use of the GraphQL library.
+ *
+ * @internal
+ */
+
+
+export function assertValidExecutionArguments(schema, document, rawVariableValues) {
+ document || devAssert(0, 'Must provide document.'); // If the schema used for execution is invalid, throw an error.
+
+ assertValidSchema(schema); // Variables, if provided, must be an object.
+
+ rawVariableValues == null || isObjectLike(rawVariableValues) || devAssert(0, '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.');
+}
+/**
+ * Constructs a ExecutionContext object from the arguments passed to
+ * execute, which we will pass throughout the other execution methods.
+ *
+ * Throws a GraphQLError if a valid execution context cannot be created.
+ *
+ * @internal
+ */
+
+export function buildExecutionContext(schema, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
+ var _definition$name, _operation$variableDe;
+
+ var operation;
+ var fragments = Object.create(null);
+
+ for (var _i2 = 0, _document$definitions2 = document.definitions; _i2 < _document$definitions2.length; _i2++) {
+ var definition = _document$definitions2[_i2];
+
+ switch (definition.kind) {
+ case Kind.OPERATION_DEFINITION:
+ if (operationName == null) {
+ if (operation !== undefined) {
+ return [new GraphQLError('Must provide operation name if query contains multiple operations.')];
+ }
+
+ operation = definition;
+ } else if (((_definition$name = definition.name) === null || _definition$name === void 0 ? void 0 : _definition$name.value) === operationName) {
+ operation = definition;
+ }
+
+ break;
+
+ case Kind.FRAGMENT_DEFINITION:
+ fragments[definition.name.value] = definition;
+ break;
+ }
+ }
+
+ if (!operation) {
+ if (operationName != null) {
+ return [new GraphQLError("Unknown operation named \"".concat(operationName, "\"."))];
+ }
+
+ return [new GraphQLError('Must provide an operation.')];
+ } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+
+
+ var variableDefinitions = (_operation$variableDe = operation.variableDefinitions) !== null && _operation$variableDe !== void 0 ? _operation$variableDe : [];
+ var coercedVariableValues = getVariableValues(schema, variableDefinitions, rawVariableValues !== null && rawVariableValues !== void 0 ? rawVariableValues : {}, {
+ maxErrors: 50
+ });
+
+ if (coercedVariableValues.errors) {
+ return coercedVariableValues.errors;
+ }
+
+ return {
+ schema: schema,
+ fragments: fragments,
+ rootValue: rootValue,
+ contextValue: contextValue,
+ operation: operation,
+ variableValues: coercedVariableValues.coerced,
+ fieldResolver: fieldResolver !== null && fieldResolver !== void 0 ? fieldResolver : defaultFieldResolver,
+ typeResolver: typeResolver !== null && typeResolver !== void 0 ? typeResolver : defaultTypeResolver,
+ errors: []
+ };
+}
+/**
+ * Implements the "Evaluating operations" section of the spec.
+ */
+
+function executeOperation(exeContext, operation, rootValue) {
+ var type = getOperationRootType(exeContext.schema, operation);
+ var fields = collectFields(exeContext, type, operation.selectionSet, Object.create(null), Object.create(null));
+ var path = undefined; // Errors from sub-fields of a NonNull type may propagate to the top level,
+ // at which point we still log the error and null the parent field, which
+ // in this case is the entire response.
+
+ try {
+ var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
+
+ if (isPromise(result)) {
+ return result.then(undefined, function (error) {
+ exeContext.errors.push(error);
+ return Promise.resolve(null);
+ });
+ }
+
+ return result;
+ } catch (error) {
+ exeContext.errors.push(error);
+ return null;
+ }
+}
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "write" mode.
+ */
+
+
+function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
+ return promiseReduce(Object.keys(fields), function (results, responseName) {
+ var fieldNodes = fields[responseName];
+ var fieldPath = addPath(path, responseName, parentType.name);
+ var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
+
+ if (result === undefined) {
+ return results;
+ }
+
+ if (isPromise(result)) {
+ return result.then(function (resolvedResult) {
+ results[responseName] = resolvedResult;
+ return results;
+ });
+ }
+
+ results[responseName] = result;
+ return results;
+ }, Object.create(null));
+}
+/**
+ * Implements the "Evaluating selection sets" section of the spec
+ * for "read" mode.
+ */
+
+
+function executeFields(exeContext, parentType, sourceValue, path, fields) {
+ var results = Object.create(null);
+ var containsPromise = false;
+
+ for (var _i4 = 0, _Object$keys2 = Object.keys(fields); _i4 < _Object$keys2.length; _i4++) {
+ var responseName = _Object$keys2[_i4];
+ var fieldNodes = fields[responseName];
+ var fieldPath = addPath(path, responseName, parentType.name);
+ var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
+
+ if (result !== undefined) {
+ results[responseName] = result;
+
+ if (isPromise(result)) {
+ containsPromise = true;
+ }
+ }
+ } // If there are no promises, we can just return the object
+
+
+ if (!containsPromise) {
+ return results;
+ } // Otherwise, results is a map from field name to the result of resolving that
+ // field, which is possibly a promise. Return a promise that will return this
+ // same map, but with any promises replaced with the values they resolved to.
+
+
+ return promiseForObject(results);
+}
+/**
+ * Given a selectionSet, adds all of the fields in that selection to
+ * the passed in map of fields, and returns it at the end.
+ *
+ * CollectFields requires the "runtime type" of an object. For a field which
+ * returns an Interface or Union type, the "runtime type" will be the actual
+ * Object type returned by that field.
+ *
+ * @internal
+ */
+
+
+export function collectFields(exeContext, runtimeType, selectionSet, fields, visitedFragmentNames) {
+ for (var _i6 = 0, _selectionSet$selecti2 = selectionSet.selections; _i6 < _selectionSet$selecti2.length; _i6++) {
+ var selection = _selectionSet$selecti2[_i6];
+
+ switch (selection.kind) {
+ case Kind.FIELD:
+ {
+ if (!shouldIncludeNode(exeContext, selection)) {
+ continue;
+ }
+
+ var name = getFieldEntryKey(selection);
+
+ if (!fields[name]) {
+ fields[name] = [];
+ }
+
+ fields[name].push(selection);
+ break;
+ }
+
+ case Kind.INLINE_FRAGMENT:
+ {
+ if (!shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(exeContext, selection, runtimeType)) {
+ continue;
+ }
+
+ collectFields(exeContext, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
+ break;
+ }
+
+ case Kind.FRAGMENT_SPREAD:
+ {
+ var fragName = selection.name.value;
+
+ if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection)) {
+ continue;
+ }
+
+ visitedFragmentNames[fragName] = true;
+ var fragment = exeContext.fragments[fragName];
+
+ if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
+ continue;
+ }
+
+ collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
+ break;
+ }
+ }
+ }
+
+ return fields;
+}
+/**
+ * Determines if a field should be included based on the @include and @skip
+ * directives, where @skip has higher precedence than @include.
+ */
+
+function shouldIncludeNode(exeContext, node) {
+ var skip = getDirectiveValues(GraphQLSkipDirective, node, exeContext.variableValues);
+
+ if ((skip === null || skip === void 0 ? void 0 : skip.if) === true) {
+ return false;
+ }
+
+ var include = getDirectiveValues(GraphQLIncludeDirective, node, exeContext.variableValues);
+
+ if ((include === null || include === void 0 ? void 0 : include.if) === false) {
+ return false;
+ }
+
+ return true;
+}
+/**
+ * Determines if a fragment is applicable to the given type.
+ */
+
+
+function doesFragmentConditionMatch(exeContext, fragment, type) {
+ var typeConditionNode = fragment.typeCondition;
+
+ if (!typeConditionNode) {
+ return true;
+ }
+
+ var conditionalType = typeFromAST(exeContext.schema, typeConditionNode);
+
+ if (conditionalType === type) {
+ return true;
+ }
+
+ if (isAbstractType(conditionalType)) {
+ return exeContext.schema.isSubType(conditionalType, type);
+ }
+
+ return false;
+}
+/**
+ * Implements the logic to compute the key of a given field's entry
+ */
+
+
+function getFieldEntryKey(node) {
+ return node.alias ? node.alias.value : node.name.value;
+}
+/**
+ * Resolves the field on the given source object. In particular, this
+ * figures out the value that the field returns by calling its resolve function,
+ * then calls completeValue to complete promises, serialize scalars, or execute
+ * the sub-selection-set for objects.
+ */
+
+
+function resolveField(exeContext, parentType, source, fieldNodes, path) {
+ var _fieldDef$resolve;
+
+ var fieldNode = fieldNodes[0];
+ var fieldName = fieldNode.name.value;
+ var fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);
+
+ if (!fieldDef) {
+ return;
+ }
+
+ var returnType = fieldDef.type;
+ var resolveFn = (_fieldDef$resolve = fieldDef.resolve) !== null && _fieldDef$resolve !== void 0 ? _fieldDef$resolve : exeContext.fieldResolver;
+ var info = buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path); // Get the resolve function, regardless of if its result is normal or abrupt (error).
+
+ try {
+ // Build a JS object of arguments from the field.arguments AST, using the
+ // variables scope to fulfill any variable references.
+ // TODO: find a way to memoize, in case this field is within a List type.
+ var args = getArgumentValues(fieldDef, fieldNodes[0], exeContext.variableValues); // The resolve function's optional third argument is a context value that
+ // is provided to every resolve function within an execution. It is commonly
+ // used to represent an authenticated user, or request-specific caches.
+
+ var _contextValue = exeContext.contextValue;
+ var result = resolveFn(source, args, _contextValue, info);
+ var completed;
+
+ if (isPromise(result)) {
+ completed = result.then(function (resolved) {
+ return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
+ });
+ } else {
+ completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
+ }
+
+ if (isPromise(completed)) {
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+ return completed.then(undefined, function (rawError) {
+ var error = locatedError(rawError, fieldNodes, pathToArray(path));
+ return handleFieldError(error, returnType, exeContext);
+ });
+ }
+
+ return completed;
+ } catch (rawError) {
+ var error = locatedError(rawError, fieldNodes, pathToArray(path));
+ return handleFieldError(error, returnType, exeContext);
+ }
+}
+/**
+ * @internal
+ */
+
+
+export function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
+ // The resolve function's optional fourth argument is a collection of
+ // information about the current execution state.
+ return {
+ fieldName: fieldDef.name,
+ fieldNodes: fieldNodes,
+ returnType: fieldDef.type,
+ parentType: parentType,
+ path: path,
+ schema: exeContext.schema,
+ fragments: exeContext.fragments,
+ rootValue: exeContext.rootValue,
+ operation: exeContext.operation,
+ variableValues: exeContext.variableValues
+ };
+}
+
+function handleFieldError(error, returnType, exeContext) {
+ // If the field type is non-nullable, then it is resolved without any
+ // protection from errors, however it still properly locates the error.
+ if (isNonNullType(returnType)) {
+ throw error;
+ } // Otherwise, error protection is applied, logging the error and resolving
+ // a null value for this field if one is encountered.
+
+
+ exeContext.errors.push(error);
+ return null;
+}
+/**
+ * Implements the instructions for completeValue as defined in the
+ * "Field entries" section of the spec.
+ *
+ * If the field type is Non-Null, then this recursively completes the value
+ * for the inner type. It throws a field error if that completion returns null,
+ * as per the "Nullability" section of the spec.
+ *
+ * If the field type is a List, then this recursively completes the value
+ * for the inner type on each item in the list.
+ *
+ * If the field type is a Scalar or Enum, ensures the completed value is a legal
+ * value of the type by calling the `serialize` method of GraphQL type
+ * definition.
+ *
+ * If the field is an abstract type, determine the runtime type of the value
+ * and then complete based on that type
+ *
+ * Otherwise, the field type expects a sub-selection set, and will complete the
+ * value by evaluating all sub-selections.
+ */
+
+
+function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // If result is an Error, throw a located error.
+ if (result instanceof Error) {
+ throw result;
+ } // If field type is NonNull, complete for inner type, and throw field error
+ // if result is null.
+
+
+ if (isNonNullType(returnType)) {
+ var completed = completeValue(exeContext, returnType.ofType, fieldNodes, info, path, result);
+
+ if (completed === null) {
+ throw new Error("Cannot return null for non-nullable field ".concat(info.parentType.name, ".").concat(info.fieldName, "."));
+ }
+
+ return completed;
+ } // If result value is null or undefined then return null.
+
+
+ if (result == null) {
+ return null;
+ } // If field type is List, complete each item in the list with the inner type
+
+
+ if (isListType(returnType)) {
+ return completeListValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
+ // returning null if serialization is not possible.
+
+
+ if (isLeafType(returnType)) {
+ return completeLeafValue(returnType, result);
+ } // If field type is an abstract type, Interface or Union, determine the
+ // runtime Object type and complete for that type.
+
+
+ if (isAbstractType(returnType)) {
+ return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // If field type is Object, execute and complete all sub-selections.
+ // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
+
+
+ if (isObjectType(returnType)) {
+ return completeObjectValue(exeContext, returnType, fieldNodes, info, path, result);
+ } // istanbul ignore next (Not reachable. All possible output types have been considered)
+
+
+ false || invariant(0, 'Cannot complete value of unexpected output type: ' + inspect(returnType));
+}
+/**
+ * Complete a list value by completing each item in the list with the
+ * inner type
+ */
+
+
+function completeListValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // This is specified as a simple map, however we're optimizing the path
+ // where the list contains no Promises by avoiding creating another Promise.
+ var itemType = returnType.ofType;
+ var containsPromise = false;
+ var completedResults = safeArrayFrom(result, function (item, index) {
+ // No need to modify the info object containing the path,
+ // since from here on it is not ever accessed by resolver functions.
+ var itemPath = addPath(path, index, undefined);
+
+ try {
+ var completedItem;
+
+ if (isPromise(item)) {
+ completedItem = item.then(function (resolved) {
+ return completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved);
+ });
+ } else {
+ completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item);
+ }
+
+ if (isPromise(completedItem)) {
+ containsPromise = true; // Note: we don't rely on a `catch` method, but we do expect "thenable"
+ // to take a second callback for the error case.
+
+ return completedItem.then(undefined, function (rawError) {
+ var error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
+ return handleFieldError(error, itemType, exeContext);
+ });
+ }
+
+ return completedItem;
+ } catch (rawError) {
+ var error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
+ return handleFieldError(error, itemType, exeContext);
+ }
+ });
+
+ if (completedResults == null) {
+ throw new GraphQLError("Expected Iterable, but did not find one for field \"".concat(info.parentType.name, ".").concat(info.fieldName, "\"."));
+ }
+
+ return containsPromise ? Promise.all(completedResults) : completedResults;
+}
+/**
+ * Complete a Scalar or Enum by serializing to a valid value, returning
+ * null if serialization is not possible.
+ */
+
+
+function completeLeafValue(returnType, result) {
+ var serializedResult = returnType.serialize(result);
+
+ if (serializedResult === undefined) {
+ throw new Error("Expected a value of type \"".concat(inspect(returnType), "\" but ") + "received: ".concat(inspect(result)));
+ }
+
+ return serializedResult;
+}
+/**
+ * Complete a value of an abstract type by determining the runtime object type
+ * of that value, then complete the value for that type.
+ */
+
+
+function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
+ var _returnType$resolveTy;
+
+ var resolveTypeFn = (_returnType$resolveTy = returnType.resolveType) !== null && _returnType$resolveTy !== void 0 ? _returnType$resolveTy : exeContext.typeResolver;
+ var contextValue = exeContext.contextValue;
+ var runtimeType = resolveTypeFn(result, contextValue, info, returnType);
+
+ if (isPromise(runtimeType)) {
+ return runtimeType.then(function (resolvedRuntimeType) {
+ return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
+ });
+ }
+
+ return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
+}
+
+function ensureValidRuntimeType(runtimeTypeOrName, exeContext, returnType, fieldNodes, info, result) {
+ if (runtimeTypeOrName == null) {
+ throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\". Either the \"").concat(returnType.name, "\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."), fieldNodes);
+ } // FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
+
+
+ var runtimeTypeName = isNamedType(runtimeTypeOrName) ? runtimeTypeOrName.name : runtimeTypeOrName;
+
+ if (typeof runtimeTypeName !== 'string') {
+ throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\" with ") + "value ".concat(inspect(result), ", received \"").concat(inspect(runtimeTypeOrName), "\"."));
+ }
+
+ var runtimeType = exeContext.schema.getType(runtimeTypeName);
+
+ if (runtimeType == null) {
+ throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a type \"").concat(runtimeTypeName, "\" that does not exist inside schema."), fieldNodes);
+ }
+
+ if (!isObjectType(runtimeType)) {
+ throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a non-object type \"").concat(runtimeTypeName, "\"."), fieldNodes);
+ }
+
+ if (!exeContext.schema.isSubType(returnType, runtimeType)) {
+ throw new GraphQLError("Runtime Object type \"".concat(runtimeType.name, "\" is not a possible type for \"").concat(returnType.name, "\"."), fieldNodes);
+ }
+
+ return runtimeType;
+}
+/**
+ * Complete an Object value by executing all sub-selections.
+ */
+
+
+function completeObjectValue(exeContext, returnType, fieldNodes, info, path, result) {
+ // If there is an isTypeOf predicate function, call it with the
+ // current result. If isTypeOf returns false, then raise an error rather
+ // than continuing execution.
+ if (returnType.isTypeOf) {
+ var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
+
+ if (isPromise(isTypeOf)) {
+ return isTypeOf.then(function (resolvedIsTypeOf) {
+ if (!resolvedIsTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+
+ return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result);
+ });
+ }
+
+ if (!isTypeOf) {
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
+ }
+ }
+
+ return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result);
+}
+
+function invalidReturnTypeError(returnType, result, fieldNodes) {
+ return new GraphQLError("Expected value of type \"".concat(returnType.name, "\" but got: ").concat(inspect(result), "."), fieldNodes);
+}
+
+function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result) {
+ // Collect sub-fields to execute to complete this value.
+ var subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
+}
+/**
+ * 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.
+ */
+
+
+var collectSubfields = memoize3(_collectSubfields);
+
+function _collectSubfields(exeContext, returnType, fieldNodes) {
+ var subFieldNodes = Object.create(null);
+ var visitedFragmentNames = Object.create(null);
+
+ for (var _i8 = 0; _i8 < fieldNodes.length; _i8++) {
+ var node = fieldNodes[_i8];
+
+ if (node.selectionSet) {
+ subFieldNodes = collectFields(exeContext, returnType, node.selectionSet, subFieldNodes, visitedFragmentNames);
+ }
+ }
+
+ return subFieldNodes;
+}
+/**
+ * If a resolveType function is not given, then a default resolve behavior is
+ * used which attempts two strategies:
+ *
+ * First, See if the provided value has a `__typename` field defined, if so, use
+ * that value as name of the resolved type.
+ *
+ * Otherwise, test each possible type for the abstract type by calling
+ * isTypeOf for the object being coerced, returning the first type that matches.
+ */
+
+
+export var defaultTypeResolver = function defaultTypeResolver(value, contextValue, info, abstractType) {
+ // First, look for `__typename`.
+ if (isObjectLike(value) && typeof value.__typename === 'string') {
+ return value.__typename;
+ } // Otherwise, test each possible type.
+
+
+ var possibleTypes = info.schema.getPossibleTypes(abstractType);
+ var promisedIsTypeOfResults = [];
+
+ for (var i = 0; i < possibleTypes.length; i++) {
+ var type = possibleTypes[i];
+
+ if (type.isTypeOf) {
+ var isTypeOfResult = type.isTypeOf(value, contextValue, info);
+
+ if (isPromise(isTypeOfResult)) {
+ promisedIsTypeOfResults[i] = isTypeOfResult;
+ } else if (isTypeOfResult) {
+ return type.name;
+ }
+ }
+ }
+
+ if (promisedIsTypeOfResults.length) {
+ return Promise.all(promisedIsTypeOfResults).then(function (isTypeOfResults) {
+ for (var _i9 = 0; _i9 < isTypeOfResults.length; _i9++) {
+ if (isTypeOfResults[_i9]) {
+ return possibleTypes[_i9].name;
+ }
+ }
+ });
+ }
+};
+/**
+ * If a resolve function is not given, then a default resolve behavior is used
+ * which takes the property of the source object of the same name as the field
+ * and returns it as the result, or if it's a function, returns the result
+ * of calling that function while passing along args and context value.
+ */
+
+export var defaultFieldResolver = function defaultFieldResolver(source, args, contextValue, info) {
+ // ensure source is a value for which property access is acceptable.
+ if (isObjectLike(source) || typeof source === 'function') {
+ var property = source[info.fieldName];
+
+ if (typeof property === 'function') {
+ return source[info.fieldName](args, contextValue, info);
+ }
+
+ return property;
+ }
+};
+/**
+ * This method looks up the field on the given type definition.
+ * It has special casing for the three introspection fields,
+ * __schema, __type and __typename. __typename is special because
+ * it can always be queried as a field, even in situations where no
+ * other fields are allowed, like on a Union. __schema and __type
+ * could get automatically added to the query type, but that would
+ * require mutating type definitions, which would cause issues.
+ *
+ * @internal
+ */
+
+export function getFieldDef(schema, parentType, fieldName) {
+ if (fieldName === SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {
+ return SchemaMetaFieldDef;
+ } else if (fieldName === TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
+ return TypeMetaFieldDef;
+ } else if (fieldName === TypeNameMetaFieldDef.name) {
+ return TypeNameMetaFieldDef;
+ }
+
+ return parentType.getFields()[fieldName];
+}
diff --git a/school/node_modules/graphql/execution/index.d.ts b/school/node_modules/graphql/execution/index.d.ts
new file mode 100644
index 0000000..d70ba3a
--- /dev/null
+++ b/school/node_modules/graphql/execution/index.d.ts
@@ -0,0 +1,13 @@
+export { pathToArray as responsePathAsArray } from '../jsutils/Path';
+
+export {
+ execute,
+ executeSync,
+ defaultFieldResolver,
+ defaultTypeResolver,
+ ExecutionArgs,
+ ExecutionResult,
+ FormattedExecutionResult,
+} from './execute';
+
+export { getDirectiveValues } from './values';
diff --git a/school/node_modules/graphql/execution/index.js b/school/node_modules/graphql/execution/index.js
new file mode 100644
index 0000000..3d5fe46
--- /dev/null
+++ b/school/node_modules/graphql/execution/index.js
@@ -0,0 +1,47 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+Object.defineProperty(exports, "responsePathAsArray", {
+ enumerable: true,
+ get: function get() {
+ return _Path.pathToArray;
+ }
+});
+Object.defineProperty(exports, "execute", {
+ enumerable: true,
+ get: function get() {
+ return _execute.execute;
+ }
+});
+Object.defineProperty(exports, "executeSync", {
+ enumerable: true,
+ get: function get() {
+ return _execute.executeSync;
+ }
+});
+Object.defineProperty(exports, "defaultFieldResolver", {
+ enumerable: true,
+ get: function get() {
+ return _execute.defaultFieldResolver;
+ }
+});
+Object.defineProperty(exports, "defaultTypeResolver", {
+ enumerable: true,
+ get: function get() {
+ return _execute.defaultTypeResolver;
+ }
+});
+Object.defineProperty(exports, "getDirectiveValues", {
+ enumerable: true,
+ get: function get() {
+ return _values.getDirectiveValues;
+ }
+});
+
+var _Path = require("../jsutils/Path.js");
+
+var _execute = require("./execute.js");
+
+var _values = require("./values.js");
diff --git a/school/node_modules/graphql/execution/index.js.flow b/school/node_modules/graphql/execution/index.js.flow
new file mode 100644
index 0000000..c8a2ee1
--- /dev/null
+++ b/school/node_modules/graphql/execution/index.js.flow
@@ -0,0 +1,17 @@
+// @flow strict
+export { pathToArray as responsePathAsArray } from '../jsutils/Path';
+
+export {
+ execute,
+ executeSync,
+ defaultFieldResolver,
+ defaultTypeResolver,
+} from './execute';
+
+export type {
+ ExecutionArgs,
+ ExecutionResult,
+ FormattedExecutionResult,
+} from './execute';
+
+export { getDirectiveValues } from './values';
diff --git a/school/node_modules/graphql/execution/index.mjs b/school/node_modules/graphql/execution/index.mjs
new file mode 100644
index 0000000..f8c087d
--- /dev/null
+++ b/school/node_modules/graphql/execution/index.mjs
@@ -0,0 +1,3 @@
+export { pathToArray as responsePathAsArray } from "../jsutils/Path.mjs";
+export { execute, executeSync, defaultFieldResolver, defaultTypeResolver } from "./execute.mjs";
+export { getDirectiveValues } from "./values.mjs";
diff --git a/school/node_modules/graphql/execution/values.d.ts b/school/node_modules/graphql/execution/values.d.ts
new file mode 100644
index 0000000..8b17b54
--- /dev/null
+++ b/school/node_modules/graphql/execution/values.d.ts
@@ -0,0 +1,65 @@
+import { Maybe } from '../jsutils/Maybe';
+
+import { GraphQLError } from '../error/GraphQLError';
+import {
+ FieldNode,
+ DirectiveNode,
+ VariableDefinitionNode,
+} from '../language/ast';
+
+import { GraphQLDirective } from '../type/directives';
+import { GraphQLSchema } from '../type/schema';
+import { GraphQLField } from '../type/definition';
+
+type CoercedVariableValues =
+ | { errors: ReadonlyArray<GraphQLError>; coerced?: never }
+ | { errors?: never; coerced: { [key: string]: any } };
+
+/**
+ * Prepares an object map of variableValues of the correct type based on the
+ * provided variable definitions and arbitrary input. If the input cannot be
+ * parsed to match the variable definitions, a GraphQLError will be thrown.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+export function getVariableValues(
+ schema: GraphQLSchema,
+ varDefNodes: ReadonlyArray<VariableDefinitionNode>,
+ inputs: { [key: string]: any },
+ options?: { maxErrors?: number },
+): CoercedVariableValues;
+
+/**
+ * Prepares an object map of argument values given a list of argument
+ * definitions and list of argument AST nodes.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+export function getArgumentValues(
+ def: GraphQLField<any, any> | GraphQLDirective,
+ node: FieldNode | DirectiveNode,
+ variableValues?: Maybe<{ [key: string]: any }>,
+): { [key: string]: any };
+
+/**
+ * Prepares an object map of argument values given a directive definition
+ * and a AST node which may contain directives. Optionally also accepts a map
+ * of variable values.
+ *
+ * If the directive does not exist on the node, returns undefined.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+export function getDirectiveValues(
+ directiveDef: GraphQLDirective,
+ node: {
+ readonly directives?: ReadonlyArray<DirectiveNode>;
+ },
+ variableValues?: Maybe<{ [key: string]: any }>,
+): undefined | { [key: string]: any };
diff --git a/school/node_modules/graphql/execution/values.js b/school/node_modules/graphql/execution/values.js
new file mode 100644
index 0000000..ac4bba9
--- /dev/null
+++ b/school/node_modules/graphql/execution/values.js
@@ -0,0 +1,228 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.getVariableValues = getVariableValues;
+exports.getArgumentValues = getArgumentValues;
+exports.getDirectiveValues = getDirectiveValues;
+
+var _find = _interopRequireDefault(require("../polyfills/find.js"));
+
+var _keyMap = _interopRequireDefault(require("../jsutils/keyMap.js"));
+
+var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
+
+var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray.js"));
+
+var _GraphQLError = require("../error/GraphQLError.js");
+
+var _kinds = require("../language/kinds.js");
+
+var _printer = require("../language/printer.js");
+
+var _definition = require("../type/definition.js");
+
+var _typeFromAST = require("../utilities/typeFromAST.js");
+
+var _valueFromAST = require("../utilities/valueFromAST.js");
+
+var _coerceInputValue = require("../utilities/coerceInputValue.js");
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * Prepares an object map of variableValues of the correct type based on the
+ * provided variable definitions and arbitrary input. If the input cannot be
+ * parsed to match the variable definitions, a GraphQLError will be thrown.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+function getVariableValues(schema, varDefNodes, inputs, options) {
+ var errors = [];
+ var maxErrors = options === null || options === void 0 ? void 0 : options.maxErrors;
+
+ try {
+ var coerced = coerceVariableValues(schema, varDefNodes, inputs, function (error) {
+ if (maxErrors != null && errors.length >= maxErrors) {
+ throw new _GraphQLError.GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
+ }
+
+ errors.push(error);
+ });
+
+ if (errors.length === 0) {
+ return {
+ coerced: coerced
+ };
+ }
+ } catch (error) {
+ errors.push(error);
+ }
+
+ return {
+ errors: errors
+ };
+}
+
+function coerceVariableValues(schema, varDefNodes, inputs, onError) {
+ var coercedValues = {};
+
+ var _loop = function _loop(_i2) {
+ var varDefNode = varDefNodes[_i2];
+ var varName = varDefNode.variable.name.value;
+ var varType = (0, _typeFromAST.typeFromAST)(schema, varDefNode.type);
+
+ if (!(0, _definition.isInputType)(varType)) {
+ // Must use input types for variables. This should be caught during
+ // validation, however is checked again here for safety.
+ var varTypeStr = (0, _printer.print)(varDefNode.type);
+ onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" expected value of type \"").concat(varTypeStr, "\" which cannot be used as an input type."), varDefNode.type));
+ return "continue";
+ }
+
+ if (!hasOwnProperty(inputs, varName)) {
+ if (varDefNode.defaultValue) {
+ coercedValues[varName] = (0, _valueFromAST.valueFromAST)(varDefNode.defaultValue, varType);
+ } else if ((0, _definition.isNonNullType)(varType)) {
+ var _varTypeStr = (0, _inspect.default)(varType);
+
+ onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" of required type \"").concat(_varTypeStr, "\" was not provided."), varDefNode));
+ }
+
+ return "continue";
+ }
+
+ var value = inputs[varName];
+
+ if (value === null && (0, _definition.isNonNullType)(varType)) {
+ var _varTypeStr2 = (0, _inspect.default)(varType);
+
+ onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" of non-null type \"").concat(_varTypeStr2, "\" must not be null."), varDefNode));
+ return "continue";
+ }
+
+ coercedValues[varName] = (0, _coerceInputValue.coerceInputValue)(value, varType, function (path, invalidValue, error) {
+ var prefix = "Variable \"$".concat(varName, "\" got invalid value ") + (0, _inspect.default)(invalidValue);
+
+ if (path.length > 0) {
+ prefix += " at \"".concat(varName).concat((0, _printPathArray.default)(path), "\"");
+ }
+
+ onError(new _GraphQLError.GraphQLError(prefix + '; ' + error.message, varDefNode, undefined, undefined, undefined, error.originalError));
+ });
+ };
+
+ for (var _i2 = 0; _i2 < varDefNodes.length; _i2++) {
+ var _ret = _loop(_i2);
+
+ if (_ret === "continue") continue;
+ }
+
+ return coercedValues;
+}
+/**
+ * Prepares an object map of argument values given a list of argument
+ * definitions and list of argument AST nodes.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+
+
+function getArgumentValues(def, node, variableValues) {
+ var _node$arguments;
+
+ var coercedValues = {}; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+
+ var argumentNodes = (_node$arguments = node.arguments) !== null && _node$arguments !== void 0 ? _node$arguments : [];
+ var argNodeMap = (0, _keyMap.default)(argumentNodes, function (arg) {
+ return arg.name.value;
+ });
+
+ for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
+ var argDef = _def$args2[_i4];
+ var name = argDef.name;
+ var argType = argDef.type;
+ var argumentNode = argNodeMap[name];
+
+ if (!argumentNode) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if ((0, _definition.isNonNullType)(argType)) {
+ throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of required type \"").concat((0, _inspect.default)(argType), "\" ") + 'was not provided.', node);
+ }
+
+ continue;
+ }
+
+ var valueNode = argumentNode.value;
+ var isNull = valueNode.kind === _kinds.Kind.NULL;
+
+ if (valueNode.kind === _kinds.Kind.VARIABLE) {
+ var variableName = valueNode.name.value;
+
+ if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if ((0, _definition.isNonNullType)(argType)) {
+ throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of required type \"").concat((0, _inspect.default)(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
+ }
+
+ continue;
+ }
+
+ isNull = variableValues[variableName] == null;
+ }
+
+ if (isNull && (0, _definition.isNonNullType)(argType)) {
+ throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat((0, _inspect.default)(argType), "\" ") + 'must not be null.', valueNode);
+ }
+
+ var coercedValue = (0, _valueFromAST.valueFromAST)(valueNode, argType, variableValues);
+
+ if (coercedValue === undefined) {
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
+ // execution. This is a runtime check to ensure execution does not
+ // continue with an invalid argument value.
+ throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat((0, _printer.print)(valueNode), "."), valueNode);
+ }
+
+ coercedValues[name] = coercedValue;
+ }
+
+ return coercedValues;
+}
+/**
+ * Prepares an object map of argument values given a directive definition
+ * and a AST node which may contain directives. Optionally also accepts a map
+ * of variable values.
+ *
+ * If the directive does not exist on the node, returns undefined.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+
+
+function getDirectiveValues(directiveDef, node, variableValues) {
+ var directiveNode = node.directives && (0, _find.default)(node.directives, function (directive) {
+ return directive.name.value === directiveDef.name;
+ });
+
+ if (directiveNode) {
+ return getArgumentValues(directiveDef, directiveNode, variableValues);
+ }
+}
+
+function hasOwnProperty(obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+}
diff --git a/school/node_modules/graphql/execution/values.js.flow b/school/node_modules/graphql/execution/values.js.flow
new file mode 100644
index 0000000..ef3e390
--- /dev/null
+++ b/school/node_modules/graphql/execution/values.js.flow
@@ -0,0 +1,267 @@
+// @flow strict
+import find from '../polyfills/find';
+
+import type { ObjMap } from '../jsutils/ObjMap';
+import keyMap from '../jsutils/keyMap';
+import inspect from '../jsutils/inspect';
+import printPathArray from '../jsutils/printPathArray';
+
+import { GraphQLError } from '../error/GraphQLError';
+
+import type {
+ FieldNode,
+ DirectiveNode,
+ VariableDefinitionNode,
+} from '../language/ast';
+import { Kind } from '../language/kinds';
+import { print } from '../language/printer';
+
+import type { GraphQLSchema } from '../type/schema';
+import type { GraphQLField } from '../type/definition';
+import type { GraphQLDirective } from '../type/directives';
+import { isInputType, isNonNullType } from '../type/definition';
+
+import { typeFromAST } from '../utilities/typeFromAST';
+import { valueFromAST } from '../utilities/valueFromAST';
+import { coerceInputValue } from '../utilities/coerceInputValue';
+
+type CoercedVariableValues =
+ | {| errors: $ReadOnlyArray<GraphQLError> |}
+ | {| coerced: { [variable: string]: mixed, ... } |};
+
+/**
+ * Prepares an object map of variableValues of the correct type based on the
+ * provided variable definitions and arbitrary input. If the input cannot be
+ * parsed to match the variable definitions, a GraphQLError will be thrown.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+export function getVariableValues(
+ schema: GraphQLSchema,
+ varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
+ inputs: { +[variable: string]: mixed, ... },
+ options?: {| maxErrors?: number |},
+): CoercedVariableValues {
+ const errors = [];
+ const maxErrors = options?.maxErrors;
+ try {
+ const coerced = coerceVariableValues(
+ schema,
+ varDefNodes,
+ inputs,
+ (error) => {
+ if (maxErrors != null && errors.length >= maxErrors) {
+ throw new GraphQLError(
+ 'Too many errors processing variables, error limit reached. Execution aborted.',
+ );
+ }
+ errors.push(error);
+ },
+ );
+
+ if (errors.length === 0) {
+ return { coerced };
+ }
+ } catch (error) {
+ errors.push(error);
+ }
+
+ return { errors };
+}
+
+function coerceVariableValues(
+ schema: GraphQLSchema,
+ varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
+ inputs: { +[variable: string]: mixed, ... },
+ onError: (GraphQLError) => void,
+): { [variable: string]: mixed, ... } {
+ const coercedValues = {};
+ for (const varDefNode of varDefNodes) {
+ const varName = varDefNode.variable.name.value;
+ const varType = typeFromAST(schema, varDefNode.type);
+ if (!isInputType(varType)) {
+ // Must use input types for variables. This should be caught during
+ // validation, however is checked again here for safety.
+ const varTypeStr = print(varDefNode.type);
+ onError(
+ new GraphQLError(
+ `Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
+ varDefNode.type,
+ ),
+ );
+ continue;
+ }
+
+ if (!hasOwnProperty(inputs, varName)) {
+ if (varDefNode.defaultValue) {
+ coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
+ } else if (isNonNullType(varType)) {
+ const varTypeStr = inspect(varType);
+ onError(
+ new GraphQLError(
+ `Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
+ varDefNode,
+ ),
+ );
+ }
+ continue;
+ }
+
+ const value = inputs[varName];
+ if (value === null && isNonNullType(varType)) {
+ const varTypeStr = inspect(varType);
+ onError(
+ new GraphQLError(
+ `Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
+ varDefNode,
+ ),
+ );
+ continue;
+ }
+
+ coercedValues[varName] = coerceInputValue(
+ value,
+ varType,
+ (path, invalidValue, error) => {
+ let prefix =
+ `Variable "$${varName}" got invalid value ` + inspect(invalidValue);
+ if (path.length > 0) {
+ prefix += ` at "${varName}${printPathArray(path)}"`;
+ }
+ onError(
+ new GraphQLError(
+ prefix + '; ' + error.message,
+ varDefNode,
+ undefined,
+ undefined,
+ undefined,
+ error.originalError,
+ ),
+ );
+ },
+ );
+ }
+
+ return coercedValues;
+}
+
+/**
+ * Prepares an object map of argument values given a list of argument
+ * definitions and list of argument AST nodes.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+export function getArgumentValues(
+ def: GraphQLField<mixed, mixed> | GraphQLDirective,
+ node: FieldNode | DirectiveNode,
+ variableValues?: ?ObjMap<mixed>,
+): { [argument: string]: mixed, ... } {
+ const coercedValues = {};
+
+ // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+ const argumentNodes = node.arguments ?? [];
+ const argNodeMap = keyMap(argumentNodes, (arg) => arg.name.value);
+
+ for (const argDef of def.args) {
+ const name = argDef.name;
+ const argType = argDef.type;
+ const argumentNode = argNodeMap[name];
+
+ if (!argumentNode) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if (isNonNullType(argType)) {
+ throw new GraphQLError(
+ `Argument "${name}" of required type "${inspect(argType)}" ` +
+ 'was not provided.',
+ node,
+ );
+ }
+ continue;
+ }
+
+ const valueNode = argumentNode.value;
+ let isNull = valueNode.kind === Kind.NULL;
+
+ if (valueNode.kind === Kind.VARIABLE) {
+ const variableName = valueNode.name.value;
+ if (
+ variableValues == null ||
+ !hasOwnProperty(variableValues, variableName)
+ ) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if (isNonNullType(argType)) {
+ throw new GraphQLError(
+ `Argument "${name}" of required type "${inspect(argType)}" ` +
+ `was provided the variable "$${variableName}" which was not provided a runtime value.`,
+ valueNode,
+ );
+ }
+ continue;
+ }
+ isNull = variableValues[variableName] == null;
+ }
+
+ if (isNull && isNonNullType(argType)) {
+ throw new GraphQLError(
+ `Argument "${name}" of non-null type "${inspect(argType)}" ` +
+ 'must not be null.',
+ valueNode,
+ );
+ }
+
+ const coercedValue = valueFromAST(valueNode, argType, variableValues);
+ if (coercedValue === undefined) {
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
+ // execution. This is a runtime check to ensure execution does not
+ // continue with an invalid argument value.
+ throw new GraphQLError(
+ `Argument "${name}" has invalid value ${print(valueNode)}.`,
+ valueNode,
+ );
+ }
+ coercedValues[name] = coercedValue;
+ }
+ return coercedValues;
+}
+
+/**
+ * Prepares an object map of argument values given a directive definition
+ * and a AST node which may contain directives. Optionally also accepts a map
+ * of variable values.
+ *
+ * If the directive does not exist on the node, returns undefined.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+export function getDirectiveValues(
+ directiveDef: GraphQLDirective,
+ node: { +directives?: $ReadOnlyArray<DirectiveNode>, ... },
+ variableValues?: ?ObjMap<mixed>,
+): void | { [argument: string]: mixed, ... } {
+ const directiveNode =
+ node.directives &&
+ find(
+ node.directives,
+ (directive) => directive.name.value === directiveDef.name,
+ );
+
+ if (directiveNode) {
+ return getArgumentValues(directiveDef, directiveNode, variableValues);
+ }
+}
+
+function hasOwnProperty(obj: mixed, prop: string): boolean {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+}
diff --git a/school/node_modules/graphql/execution/values.mjs b/school/node_modules/graphql/execution/values.mjs
new file mode 100644
index 0000000..485a210
--- /dev/null
+++ b/school/node_modules/graphql/execution/values.mjs
@@ -0,0 +1,206 @@
+import find from "../polyfills/find.mjs";
+import keyMap from "../jsutils/keyMap.mjs";
+import inspect from "../jsutils/inspect.mjs";
+import printPathArray from "../jsutils/printPathArray.mjs";
+import { GraphQLError } from "../error/GraphQLError.mjs";
+import { Kind } from "../language/kinds.mjs";
+import { print } from "../language/printer.mjs";
+import { isInputType, isNonNullType } from "../type/definition.mjs";
+import { typeFromAST } from "../utilities/typeFromAST.mjs";
+import { valueFromAST } from "../utilities/valueFromAST.mjs";
+import { coerceInputValue } from "../utilities/coerceInputValue.mjs";
+
+/**
+ * Prepares an object map of variableValues of the correct type based on the
+ * provided variable definitions and arbitrary input. If the input cannot be
+ * parsed to match the variable definitions, a GraphQLError will be thrown.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+export function getVariableValues(schema, varDefNodes, inputs, options) {
+ var errors = [];
+ var maxErrors = options === null || options === void 0 ? void 0 : options.maxErrors;
+
+ try {
+ var coerced = coerceVariableValues(schema, varDefNodes, inputs, function (error) {
+ if (maxErrors != null && errors.length >= maxErrors) {
+ throw new GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
+ }
+
+ errors.push(error);
+ });
+
+ if (errors.length === 0) {
+ return {
+ coerced: coerced
+ };
+ }
+ } catch (error) {
+ errors.push(error);
+ }
+
+ return {
+ errors: errors
+ };
+}
+
+function coerceVariableValues(schema, varDefNodes, inputs, onError) {
+ var coercedValues = {};
+
+ var _loop = function _loop(_i2) {
+ var varDefNode = varDefNodes[_i2];
+ var varName = varDefNode.variable.name.value;
+ var varType = typeFromAST(schema, varDefNode.type);
+
+ if (!isInputType(varType)) {
+ // Must use input types for variables. This should be caught during
+ // validation, however is checked again here for safety.
+ var varTypeStr = print(varDefNode.type);
+ onError(new GraphQLError("Variable \"$".concat(varName, "\" expected value of type \"").concat(varTypeStr, "\" which cannot be used as an input type."), varDefNode.type));
+ return "continue";
+ }
+
+ if (!hasOwnProperty(inputs, varName)) {
+ if (varDefNode.defaultValue) {
+ coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
+ } else if (isNonNullType(varType)) {
+ var _varTypeStr = inspect(varType);
+
+ onError(new GraphQLError("Variable \"$".concat(varName, "\" of required type \"").concat(_varTypeStr, "\" was not provided."), varDefNode));
+ }
+
+ return "continue";
+ }
+
+ var value = inputs[varName];
+
+ if (value === null && isNonNullType(varType)) {
+ var _varTypeStr2 = inspect(varType);
+
+ onError(new GraphQLError("Variable \"$".concat(varName, "\" of non-null type \"").concat(_varTypeStr2, "\" must not be null."), varDefNode));
+ return "continue";
+ }
+
+ coercedValues[varName] = coerceInputValue(value, varType, function (path, invalidValue, error) {
+ var prefix = "Variable \"$".concat(varName, "\" got invalid value ") + inspect(invalidValue);
+
+ if (path.length > 0) {
+ prefix += " at \"".concat(varName).concat(printPathArray(path), "\"");
+ }
+
+ onError(new GraphQLError(prefix + '; ' + error.message, varDefNode, undefined, undefined, undefined, error.originalError));
+ });
+ };
+
+ for (var _i2 = 0; _i2 < varDefNodes.length; _i2++) {
+ var _ret = _loop(_i2);
+
+ if (_ret === "continue") continue;
+ }
+
+ return coercedValues;
+}
+/**
+ * Prepares an object map of argument values given a list of argument
+ * definitions and list of argument AST nodes.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ *
+ * @internal
+ */
+
+
+export function getArgumentValues(def, node, variableValues) {
+ var _node$arguments;
+
+ var coercedValues = {}; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
+
+ var argumentNodes = (_node$arguments = node.arguments) !== null && _node$arguments !== void 0 ? _node$arguments : [];
+ var argNodeMap = keyMap(argumentNodes, function (arg) {
+ return arg.name.value;
+ });
+
+ for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
+ var argDef = _def$args2[_i4];
+ var name = argDef.name;
+ var argType = argDef.type;
+ var argumentNode = argNodeMap[name];
+
+ if (!argumentNode) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if (isNonNullType(argType)) {
+ throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + 'was not provided.', node);
+ }
+
+ continue;
+ }
+
+ var valueNode = argumentNode.value;
+ var isNull = valueNode.kind === Kind.NULL;
+
+ if (valueNode.kind === Kind.VARIABLE) {
+ var variableName = valueNode.name.value;
+
+ if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
+ if (argDef.defaultValue !== undefined) {
+ coercedValues[name] = argDef.defaultValue;
+ } else if (isNonNullType(argType)) {
+ throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
+ }
+
+ continue;
+ }
+
+ isNull = variableValues[variableName] == null;
+ }
+
+ if (isNull && isNonNullType(argType)) {
+ throw new GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat(inspect(argType), "\" ") + 'must not be null.', valueNode);
+ }
+
+ var coercedValue = valueFromAST(valueNode, argType, variableValues);
+
+ if (coercedValue === undefined) {
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
+ // execution. This is a runtime check to ensure execution does not
+ // continue with an invalid argument value.
+ throw new GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat(print(valueNode), "."), valueNode);
+ }
+
+ coercedValues[name] = coercedValue;
+ }
+
+ return coercedValues;
+}
+/**
+ * Prepares an object map of argument values given a directive definition
+ * and a AST node which may contain directives. Optionally also accepts a map
+ * of variable values.
+ *
+ * If the directive does not exist on the node, returns undefined.
+ *
+ * Note: The returned value is a plain Object with a prototype, since it is
+ * exposed to user code. Care should be taken to not pull values from the
+ * Object prototype.
+ */
+
+export function getDirectiveValues(directiveDef, node, variableValues) {
+ var directiveNode = node.directives && find(node.directives, function (directive) {
+ return directive.name.value === directiveDef.name;
+ });
+
+ if (directiveNode) {
+ return getArgumentValues(directiveDef, directiveNode, variableValues);
+ }
+}
+
+function hasOwnProperty(obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+}