diff --git a/website/pages/api-v16/error.mdx b/website/pages/api-v16/error.mdx index 1338d321de..09f5e746a6 100644 --- a/website/pages/api-v16/error.mdx +++ b/website/pages/api-v16/error.mdx @@ -56,7 +56,7 @@ class GraphQLError extends Error { source?: Source, positions?: number[], originalError?: Error, - extensions?: { [key: string]: mixed }, + extensions?: Record, ); } ``` diff --git a/website/pages/api-v16/execution.mdx b/website/pages/api-v16/execution.mdx index 2810ed183a..4723513d23 100644 --- a/website/pages/api-v16/execution.mdx +++ b/website/pages/api-v16/execution.mdx @@ -29,14 +29,28 @@ const { execute } = require('graphql'); // CommonJS ### execute ```ts -export function execute( - schema: GraphQLSchema, - documentAST: Document, - rootValue?: mixed, - contextValue?: mixed, - variableValues?: { [key: string]: mixed }, - operationName?: string, -): MaybePromise; +export function execute({ + schema, + document + rootValue, + contextValue, + variableValues, + operationName, + options, +}: ExecutionParams): MaybePromise; + +type ExecutionParams = { + schema: GraphQLSchema; + document: Document; + rootValue?: unknown; + contextValue?: unknown; + variableValues?: Record; + operationName?: string; + options?: { + /** Set the maximum number of errors allowed for coercing (defaults to 50). */ + maxCoercionErrors?: number; + } +}; type MaybePromise = Promise | T; @@ -50,6 +64,20 @@ interface ExecutionResult< } ``` +We have another approach with positional arguments, this is however deprecated and set +to be removed in v17. + +```ts +export function execute( + schema: GraphQLSchema, + documentAST: Document, + rootValue?: unknown, + contextValue?: unknown, + variableValues?: Record, + operationName?: string, +): MaybePromise; +``` + Implements the "Evaluating requests" section of the GraphQL specification. Returns a Promise that will eventually be resolved and never rejected. @@ -63,22 +91,62 @@ non-empty array if an error occurred. ### executeSync +This is a short-hand method that will call `execute` and when the response can +be returned synchronously it will be returned, when a `Promise` is returned this +method will throw an error. + +```ts +export function executeSync({ + schema, + document, + rootValue, + contextValue, + variableValues, + operationName, + options, +}: ExecutionParams): MaybePromise; + +type ExecutionParams = { + schema: GraphQLSchema; + document: Document; + rootValue?: unknown; + contextValue?: unknown; + variableValues?: Record; + operationName?: string; + options?: { + /** Set the maximum number of errors allowed for coercing (defaults to 50). */ + maxCoercionErrors?: number; + } +}; + +type MaybePromise = Promise | T; + +interface ExecutionResult< + TData = ObjMap, + TExtensions = ObjMap, +> { + errors?: ReadonlyArray; + data?: TData | null; + extensions?: TExtensions; +} +``` + +We have another approach with positional arguments, this is however deprecated and set +to be removed in v17. + ```ts export function executeSync( schema: GraphQLSchema, documentAST: Document, - rootValue?: mixed, - contextValue?: mixed, - variableValues?: { [key: string]: mixed }, + rootValue?: unknown, + contextValue?: unknown, + variableValues?: Record, operationName?: string, ): ExecutionResult; - -type ExecutionResult = { - data: Object; - errors?: GraphQLError[]; -}; ``` -This is a short-hand method that will call `execute` and when the response can -be returned synchronously it will be returned, when a `Promise` is returned this -method will throw an error. +#### Execution options + +##### maxCoercionErrors + +Set the maximum number of errors allowed for coercing variables, this implements a default limit of 50 errors.