Merge pull request #19591 from APIs-guru/executeArgs

[GraphQL] Overloading of 'graphql' and 'execute' functions
This commit is contained in:
Arthur Ozga
2017-09-14 14:27:40 -07:00
committed by GitHub
4 changed files with 39 additions and 4 deletions

View File

@@ -36,6 +36,16 @@ export interface ExecutionResult {
errors?: GraphQLError[];
}
export type ExecutionArgs = {
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: {[key: string]: any},
operationName?: string,
fieldResolver?: GraphQLFieldResolver<any, any>
};
/**
* Implements the "Evaluating requests" section of the GraphQL specification.
*
@@ -43,7 +53,10 @@ export interface ExecutionResult {
*
* 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(
schema: GraphQLSchema,
document: DocumentNode,

View File

@@ -2,6 +2,7 @@ export {
execute,
defaultFieldResolver,
responsePathAsArray,
ExecutionArgs,
ExecutionResult
} from './execute';

View File

@@ -1,3 +1,5 @@
import { Source } from './language/source';
import { GraphQLFieldResolver } from './type/definition';
import { GraphQLSchema } from './type/schema';
import { ExecutionResult } from './execution/execute';
@@ -10,9 +12,11 @@ import { ExecutionResult } from './execution/execute';
* may wish to separate the validation and execution phases to a static time
* tooling step, and a server runtime step.
*
* Accepts either an object with named arguments, or individual arguments:
*
* schema:
* The GraphQL type system to use when validating and executing a query.
* requestString:
* source:
* A GraphQL language formatted string representing the requested operation.
* rootValue:
* The value provided as the first argument to resolver functions on the top
@@ -24,14 +28,30 @@ import { ExecutionResult } from './execution/execute';
* The name of the operation to use if requestString contains multiple
* possible operations. Can be omitted if requestString contains only
* one operation.
* fieldResolver:
* A resolver function to use when one is not provided by the schema.
* If not provided, the default field resolver is used (which looks for a
* value or method on the source value with the field's name).
*/
export function graphql(
export function graphql(args: {
schema: GraphQLSchema,
requestString: string,
source: string | Source,
rootValue?: any,
contextValue?: any,
variableValues?: {
[key: string]: any
},
operationName?: string
operationName?: string,
fieldResolver?: GraphQLFieldResolver<any, any>
}): Promise<ExecutionResult>;
export function graphql(
schema: GraphQLSchema,
source: string | Source,
rootValue?: any,
contextValue?: any,
variableValues?: {
[key: string]: any
},
operationName?: string,
fieldResolver?: GraphQLFieldResolver<any, any>
): Promise<ExecutionResult>;

View File

@@ -30,6 +30,7 @@ export {
defaultFieldResolver,
responsePathAsArray,
getDirectiveValues,
ExecutionArgs,
ExecutionResult,
} from './execution';