Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/pages/api-v16/error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GraphQLError extends Error {
source?: Source,
positions?: number[],
originalError?: Error,
extensions?: { [key: string]: mixed },
extensions?: Record<string, unknown>,
);
}
```
Expand Down
106 changes: 87 additions & 19 deletions website/pages/api-v16/execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutionResult>;
export function execute({
schema,
documentAST,
rootValue,
contextValue,
variableValues,
operationName,
options,
}: ExecutionParams): MaybePromise<ExecutionResult>;

type ExecutionParams = {
schema: GraphQLSchema;
document: Document;
rootValue?: unknown;
contextValue?: unknown;
variableValues?: Record<string, unknown>;
operationName?: string;
options?: {
/** Set the maximum number of errors allowed for coercing (defaults to 50). */
maxCoercionErrors?: number;
}
};

type MaybePromise<T> = Promise<T> | T;

Expand All @@ -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<string, unknown>,
operationName?: string,
): MaybePromise<ExecutionResult>;
```

Implements the "Evaluating requests" section of the GraphQL specification.

Returns a Promise that will eventually be resolved and never rejected.
Expand All @@ -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,
documentAST,
rootValue,
contextValue,
variableValues,
operationName,
options,
}: ExecutionParams): MaybePromise<ExecutionResult>;

type ExecutionParams = {
schema: GraphQLSchema;
document: Document;
rootValue?: unknown;
contextValue?: unknown;
variableValues?: Record<string, unknown>;
operationName?: string;
options?: {
/** Set the maximum number of errors allowed for coercing (defaults to 50). */
maxCoercionErrors?: number;
}
};

type MaybePromise<T> = Promise<T> | T;

interface ExecutionResult<
TData = ObjMap<unknown>,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLError>;
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<string, unknown>,
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.