Skip to content

Commit 7dd7812

Browse files
authored
Update docs for execution options (#4368)
1 parent 8025494 commit 7dd7812

File tree

2 files changed

+88
-20
lines changed

2 files changed

+88
-20
lines changed

website/pages/api-v16/error.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GraphQLError extends Error {
5656
source?: Source,
5757
positions?: number[],
5858
originalError?: Error,
59-
extensions?: { [key: string]: mixed },
59+
extensions?: Record<string, unknown>,
6060
);
6161
}
6262
```

website/pages/api-v16/execution.mdx

+87-19
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,28 @@ const { execute } = require('graphql'); // CommonJS
2929
### execute
3030

3131
```ts
32-
export function execute(
33-
schema: GraphQLSchema,
34-
documentAST: Document,
35-
rootValue?: mixed,
36-
contextValue?: mixed,
37-
variableValues?: { [key: string]: mixed },
38-
operationName?: string,
39-
): MaybePromise<ExecutionResult>;
32+
export function execute({
33+
schema,
34+
document
35+
rootValue,
36+
contextValue,
37+
variableValues,
38+
operationName,
39+
options,
40+
}: ExecutionParams): MaybePromise<ExecutionResult>;
41+
42+
type ExecutionParams = {
43+
schema: GraphQLSchema;
44+
document: Document;
45+
rootValue?: unknown;
46+
contextValue?: unknown;
47+
variableValues?: Record<string, unknown>;
48+
operationName?: string;
49+
options?: {
50+
/** Set the maximum number of errors allowed for coercing (defaults to 50). */
51+
maxCoercionErrors?: number;
52+
}
53+
};
4054

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

@@ -50,6 +64,20 @@ interface ExecutionResult<
5064
}
5165
```
5266

67+
We have another approach with positional arguments, this is however deprecated and set
68+
to be removed in v17.
69+
70+
```ts
71+
export function execute(
72+
schema: GraphQLSchema,
73+
documentAST: Document,
74+
rootValue?: unknown,
75+
contextValue?: unknown,
76+
variableValues?: Record<string, unknown>,
77+
operationName?: string,
78+
): MaybePromise<ExecutionResult>;
79+
```
80+
5381
Implements the "Evaluating requests" section of the GraphQL specification.
5482

5583
Returns a Promise that will eventually be resolved and never rejected.
@@ -63,22 +91,62 @@ non-empty array if an error occurred.
6391

6492
### executeSync
6593

94+
This is a short-hand method that will call `execute` and when the response can
95+
be returned synchronously it will be returned, when a `Promise` is returned this
96+
method will throw an error.
97+
98+
```ts
99+
export function executeSync({
100+
schema,
101+
document,
102+
rootValue,
103+
contextValue,
104+
variableValues,
105+
operationName,
106+
options,
107+
}: ExecutionParams): MaybePromise<ExecutionResult>;
108+
109+
type ExecutionParams = {
110+
schema: GraphQLSchema;
111+
document: Document;
112+
rootValue?: unknown;
113+
contextValue?: unknown;
114+
variableValues?: Record<string, unknown>;
115+
operationName?: string;
116+
options?: {
117+
/** Set the maximum number of errors allowed for coercing (defaults to 50). */
118+
maxCoercionErrors?: number;
119+
}
120+
};
121+
122+
type MaybePromise<T> = Promise<T> | T;
123+
124+
interface ExecutionResult<
125+
TData = ObjMap<unknown>,
126+
TExtensions = ObjMap<unknown>,
127+
> {
128+
errors?: ReadonlyArray<GraphQLError>;
129+
data?: TData | null;
130+
extensions?: TExtensions;
131+
}
132+
```
133+
134+
We have another approach with positional arguments, this is however deprecated and set
135+
to be removed in v17.
136+
66137
```ts
67138
export function executeSync(
68139
schema: GraphQLSchema,
69140
documentAST: Document,
70-
rootValue?: mixed,
71-
contextValue?: mixed,
72-
variableValues?: { [key: string]: mixed },
141+
rootValue?: unknown,
142+
contextValue?: unknown,
143+
variableValues?: Record<string, unknown>,
73144
operationName?: string,
74145
): ExecutionResult;
75-
76-
type ExecutionResult = {
77-
data: Object;
78-
errors?: GraphQLError[];
79-
};
80146
```
81147

82-
This is a short-hand method that will call `execute` and when the response can
83-
be returned synchronously it will be returned, when a `Promise` is returned this
84-
method will throw an error.
148+
#### Execution options
149+
150+
##### maxCoercionErrors
151+
152+
Set the maximum number of errors allowed for coercing variables, this implements a default limit of 50 errors.

0 commit comments

Comments
 (0)