update graphql/execution/* -> v0.13.2.

https://github.com/graphql/graphql-js/tree/v0.13.2/src/execution
This commit is contained in:
Firede
2018-03-28 00:13:02 +08:00
parent 9e573562f8
commit 323e993b8f
2 changed files with 141 additions and 25 deletions

View File

@@ -1,6 +1,12 @@
import { GraphQLError, locatedError } from "../error";
import { GraphQLSchema } from "../type/schema";
import { GraphQLField, GraphQLFieldResolver, ResponsePath } from "../type/definition";
import {
GraphQLField,
GraphQLFieldResolver,
ResponsePath,
GraphQLObjectType,
GraphQLResolveInfo,
} from "../type/definition";
import {
DirectiveNode,
DocumentNode,
@@ -10,6 +16,8 @@ import {
InlineFragmentNode,
FragmentDefinitionNode,
} from "../language/ast";
import { MaybePromise } from "../jsutils/MaybePromise";
/**
* Data that must be available at all points during query execution.
*
@@ -20,6 +28,7 @@ export interface ExecutionContext {
schema: GraphQLSchema;
fragments: { [key: string]: FragmentDefinitionNode };
rootValue: any;
contextValue: any;
operation: OperationDefinitionNode;
variableValues: { [key: string]: any };
fieldResolver: GraphQLFieldResolver<any, any>;
@@ -27,15 +36,14 @@ export interface ExecutionContext {
}
/**
* The result of execution. `data` is the result of executing the
* query, `extensions` represents additional metadata, `errors` is
* null if no errors occurred, and is a
* non-empty array if an error occurred.
* 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.
*/
export interface ExecutionResult {
errors?: ReadonlyArray<GraphQLError>;
data?: { [key: string]: any };
extensions?: { [key: string]: any };
errors?: GraphQLError[];
}
export type ExecutionArgs = {
@@ -43,41 +51,114 @@ export type ExecutionArgs = {
document: DocumentNode;
rootValue?: any;
contextValue?: any;
variableValues?: { [key: string]: any };
operationName?: string;
fieldResolver?: GraphQLFieldResolver<any, any>;
variableValues?: { [key: string]: any } | void;
operationName?: string | void;
fieldResolver?: GraphQLFieldResolver<any, any> | void;
};
/**
* Implements the "Evaluating requests" section of the GraphQL specification.
*
* Returns a Promise that will eventually be resolved and never rejected.
* 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): Promise<ExecutionResult>;
export function execute(args: ExecutionArgs): MaybePromise<ExecutionResult>;
export function execute(
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: {
[key: string]: any;
},
operationName?: string,
fieldResolver?: GraphQLFieldResolver<any, any>
): Promise<ExecutionResult>;
variableValues?: { [key: string]: any } | void,
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void
): MaybePromise<ExecutionResult>;
/**
* Given a ResponsePath (found in the `path` entry in the information provided
* as the last argument to a field resolver), return an Array of the path keys.
*/
export function responsePathAsArray(path: ResponsePath): Array<string | number>;
export function responsePathAsArray(path: ResponsePath): ReadonlyArray<string | number>;
export function addPath(prev: ResponsePath, key: string | number): any;
/**
* Given a ResponsePath and a key, return a new ResponsePath containing the
* new key.
*/
export function addPath(
prev: ResponsePath | undefined,
key: string | number
): { prev: ResponsePath | undefined; key: string | number };
/**
* Essential assertions before executing to provide developer feedback for
* improper use of the GraphQL library.
*/
export function assertValidExecutionArguments(
schema: GraphQLSchema,
document: DocumentNode,
rawVariableValues: { [key: string]: any } | void
): 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: { [key: string]: any } | void,
operationName: string | void,
fieldResolver: GraphQLFieldResolver<any, any> | void
): ReadonlyArray<GraphQLError> | ExecutionContext;
/**
* Extracts the root type of the operation from the schema.
*/
export function getOperationRootType(schema: GraphQLSchema, operation: OperationDefinitionNode): GraphQLObjectType;
/**
* 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: ResponsePath
): GraphQLResolveInfo;
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
// function. Returns the result of resolveFn or the abrupt-return Error object.
export function resolveFieldValueOrError<TSource>(
exeContext: ExecutionContext,
fieldDef: GraphQLField<TSource, any>,
fieldNodes: ReadonlyArray<FieldNode>,
resolveFn: GraphQLFieldResolver<TSource, any>,
source: TSource,
info: GraphQLResolveInfo
): Error | any;
/**
* If a resolve function is not given, then a default resolve behavior is used
@@ -86,3 +167,18 @@ export function addPath(prev: ResponsePath, key: string | number): any;
* 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 defintion.
* 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
): GraphQLField<any, any> | void;

View File

@@ -1,27 +1,41 @@
import { GraphQLError } from "../error";
import { GraphQLInputType, GraphQLField, GraphQLArgument } from "../type/definition";
import { GraphQLDirective } from "../type/directives";
import { GraphQLSchema } from "../type/schema";
import { FieldNode, DirectiveNode, VariableDefinitionNode } from "../language/ast";
interface CoercedVariableValues {
errors: ReadonlyArray<GraphQLError> | undefined;
coerced: { [key: string]: any } | undefined;
}
/**
* 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: VariableDefinitionNode[],
inputs: { [key: string]: any }
): { [key: string]: any };
): 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?: { [key: string]: any }
variableValues?: { [key: string]: any } | void
): { [key: string]: any };
/**
@@ -30,9 +44,15 @@ export function getArgumentValues(
* 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?: Array<DirectiveNode> },
variableValues?: { [key: string]: any }
): void | { [key: string]: any };
node: {
readonly directives?: ReadonlyArray<DirectiveNode>;
},
variableValues?: { [key: string]: any } | void
): undefined | { [key: string]: any };