From 5899fa54c225b4b8d1d505ae4c782c8de810533b Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 6 Sep 2017 16:58:09 +0300 Subject: [PATCH] [GraphQL] Overloading of 'graphql' and 'execute' functions --- types/graphql/execution/execute.d.ts | 13 +++++++++++++ types/graphql/execution/index.d.ts | 1 + types/graphql/graphql.d.ts | 28 ++++++++++++++++++++++++---- types/graphql/index.d.ts | 1 + 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/types/graphql/execution/execute.d.ts b/types/graphql/execution/execute.d.ts index a0181bdf50..6d02b82124 100644 --- a/types/graphql/execution/execute.d.ts +++ b/types/graphql/execution/execute.d.ts @@ -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 +}; + /** * 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; export function execute( schema: GraphQLSchema, document: DocumentNode, diff --git a/types/graphql/execution/index.d.ts b/types/graphql/execution/index.d.ts index 82d6bce853..4bf4e395ab 100644 --- a/types/graphql/execution/index.d.ts +++ b/types/graphql/execution/index.d.ts @@ -2,6 +2,7 @@ export { execute, defaultFieldResolver, responsePathAsArray, + ExecutionArgs, ExecutionResult } from './execute'; diff --git a/types/graphql/graphql.d.ts b/types/graphql/graphql.d.ts index d0053f6121..f5469d7d8c 100644 --- a/types/graphql/graphql.d.ts +++ b/types/graphql/graphql.d.ts @@ -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 +}): Promise; +export function graphql( + schema: GraphQLSchema, + source: string | Source, + rootValue?: any, + contextValue?: any, + variableValues?: { + [key: string]: any + }, + operationName?: string, + fieldResolver?: GraphQLFieldResolver ): Promise; diff --git a/types/graphql/index.d.ts b/types/graphql/index.d.ts index e85060bab5..7443de98b3 100644 --- a/types/graphql/index.d.ts +++ b/types/graphql/index.d.ts @@ -29,6 +29,7 @@ export { defaultFieldResolver, responsePathAsArray, getDirectiveValues, + ExecutionArgs, ExecutionResult, } from './execution';