Skip to content

Commit ec23905

Browse files
authored
docs: refresh website with broader execution/tracing update (#4794)
1 parent f8680fa commit ec23905

2 files changed

Lines changed: 81 additions & 55 deletions

File tree

website/pages/api-v17/execution.mdx

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ Returns either a synchronous ExecutionResult (if all encountered resolvers
161161
are synchronous), or a Promise of an ExecutionResult that will eventually be
162162
resolved and never rejected.
163163

164-
If the arguments to this function do not result in a legal execution context,
165-
a GraphQLError will be thrown immediately explaining the invalid input.
164+
If the schema is invalid, an error will be thrown immediately. GraphQL
165+
request errors, including missing operations and variable coercion errors,
166+
are returned in an errors-only ExecutionResult.
166167

167168
Field errors are collected into the response instead of rejecting the
168169
returned promise. Only the field that produced the error and its descendants
@@ -251,17 +252,18 @@ result; // => { data: { greeting: 'Hello, Ada!' } }
251252

252253
Implements the "Executing operations" section of the spec.
253254

254-
Returns a Promise that will eventually resolve to the data described by
255-
The "Response" section of the GraphQL specification.
255+
Returns either a synchronous ExecutionResult, or a Promise for an
256+
ExecutionResult, described by the "Response" section of the GraphQL
257+
specification.
256258

257-
If errors are encountered while executing a GraphQL field, only that
258-
field and its descendants will be omitted, and sibling fields will still
259-
be executed. An execution which encounters errors will still result in a
260-
resolved Promise.
259+
If errors are encountered while executing a GraphQL field, only that field
260+
and its descendants will be omitted, and sibling fields will still be
261+
executed. These field errors are collected into the returned result instead
262+
of being thrown or rejecting the returned promise.
261263

262-
Errors from sub-fields of a NonNull type may propagate to the top level,
263-
at which point we still log the error and null the parent field, which
264-
in this case is the entire response.
264+
Errors from sub-fields of a NonNull type may propagate to the top level, at
265+
which point we still collect the error and null the parent field, which in
266+
this case is the entire response.
265267

266268
**Signature:**
267269

@@ -408,6 +410,9 @@ result; // => { data: { greeting: 'Hello' } }
408410

409411
Executes a subscription operation once for a single source event.
410412

413+
Field errors are collected into the returned result instead of being thrown
414+
or rejecting the returned promise.
415+
411416
**Signature:**
412417

413418
<ApiSignature parts={[["name", "executeSubscriptionEvent"], "(\n ", ["parameter", "validatedExecutionArgs"], ": ", ["link", "ValidatedSubscriptionArgs", "/api-v17/execution#validatedsubscriptionargs"], ",\n): ", ["type", "PromiseOrValue"], "\u003c", ["link", "ExecutionResult", "/api-v17/execution#executionresult"], "\u003e;"]} />
@@ -489,21 +494,22 @@ result; // => { data: { greeting: 'Hello' } }
489494

490495
Implements the "Subscribe" algorithm described in the GraphQL specification.
491496

492-
Returns a Promise that resolves to either an AsyncIterator (if successful)
493-
or an ExecutionResult (error). The promise will be rejected if the schema or
494-
other arguments to this function are invalid, or if the resolved event stream
495-
is not an async iterable.
497+
Returns either an AsyncGenerator (if successful), an ExecutionResult (error),
498+
or a Promise for one of those results. The call will throw immediately if
499+
the schema is invalid or the selected operation is not a subscription.
496500

497-
If the client-provided arguments to this function do not result in a
498-
compliant subscription, a GraphQL Response (ExecutionResult) with descriptive
499-
errors and no data will be returned.
501+
GraphQL request errors, including missing operations and variable coercion
502+
errors, return or resolve to a GraphQL Response (ExecutionResult) with
503+
descriptive errors and no data.
500504

501505
If the source stream could not be created due to faulty subscription resolver
502-
logic or underlying systems, the promise will resolve to a single
503-
ExecutionResult containing `errors` and no `data`.
506+
logic, a non-async-iterable resolver result, or a system error, the
507+
function will return or resolve to a single ExecutionResult containing
508+
`errors` and no `data`.
504509

505-
If the operation succeeded, the promise resolves to an AsyncIterator, which
506-
yields a stream of ExecutionResults representing the response stream.
510+
If the operation succeeded, the function returns or resolves to an
511+
AsyncGenerator, which yields a stream of ExecutionResults representing the
512+
response stream.
507513

508514
This function does not support incremental delivery (`@defer` and `@stream`).
509515
If an operation which would defer or stream data is executed with this
@@ -657,21 +663,20 @@ Implements the "CreateSourceEventStream" algorithm described in the
657663
GraphQL specification, resolving the subscription source event stream for a
658664
previously validated subscription request.
659665

660-
Returns a Promise that resolves to either an AsyncIterable (if successful)
661-
or an ExecutionResult (error). The promise will be rejected if the validated
662-
execution arguments are invalid, or if the resolved event stream is not an
663-
async iterable.
666+
Returns either an AsyncIterable (if successful), an ExecutionResult (error),
667+
or a Promise for one of those results. The call will throw immediately if
668+
it is not passed validated execution arguments.
664669

665-
If the client-provided arguments to this function do not result in a
666-
compliant subscription, a GraphQL Response (ExecutionResult) with
667-
descriptive errors and no data will be returned.
670+
If the validated arguments do not result in a compliant subscription, a
671+
GraphQL Response (ExecutionResult) with descriptive errors and no data will
672+
be returned.
668673

669674
If the source stream could not be created due to faulty subscription
670-
resolver logic or underlying systems, the promise will resolve to a single
671-
ExecutionResult containing `errors` and no `data`.
675+
resolver logic or a system error, the function will return or
676+
resolve to a single ExecutionResult containing `errors` and no `data`.
672677

673-
If the operation succeeded, the promise resolves to the AsyncIterable for the
674-
event stream returned by the resolver.
678+
If the operation succeeded, the function returns or resolves to the
679+
AsyncIterable for the event stream returned by the resolver.
675680

676681
A Source Event Stream represents a sequence of events, each of which triggers
677682
a GraphQL execution for that event.
@@ -764,12 +769,11 @@ Symbol.asyncIterator in stream; // => true
764769

765770
#### validateExecutionArgs()
766771

767-
Constructs a ExecutionContext object from the arguments passed to
768-
execute, which we will pass throughout the other execution methods.
769-
770-
Throws a GraphQLError if a valid execution context cannot be created.
772+
Validates the arguments passed to execute, subscribe, and their lower-level
773+
helpers.
771774

772-
TODO: consider no longer exporting this function
775+
Throws if the schema is invalid. GraphQL request errors, including variable
776+
coercion errors, are returned as a GraphQLError array.
773777

774778
**Signature:**
775779

@@ -873,6 +877,10 @@ validatedArgs.hideSuggestions; // => true
873877

874878
Validates execution arguments for a subscription operation.
875879

880+
Throws if the schema is invalid or the selected operation is not a
881+
subscription. GraphQL request errors, including variable coercion errors, are
882+
returned as a GraphQLError array.
883+
876884
**Signature:**
877885

878886
<ApiSignature parts={[["name", "validateSubscriptionArgs"], "(\n ", ["parameter", "args"], ": ", ["link", "ExecutionArgs", "/api-v17/execution#executionargs"], ",\n): ", ["link", "ValidatedSubscriptionArgs", "/api-v17/execution#validatedsubscriptionargs"], " \u007c ", ["keyword", "readonly"], " ", ["link", "GraphQLError", "/api-v17/error#graphqlerror"], "[];"]} />
@@ -1556,8 +1564,9 @@ This function returns either a single ExecutionResult, or an
15561564
ExperimentalIncrementalExecutionResults object containing an `initialResult`
15571565
and a stream of `subsequentResults`.
15581566

1559-
If the arguments to this function do not result in a legal execution context,
1560-
a GraphQLError will be thrown immediately explaining the invalid input.
1567+
If the schema is invalid, an error will be thrown immediately. GraphQL
1568+
request errors, including missing operations and variable coercion errors,
1569+
are returned in an errors-only ExecutionResult.
15611570

15621571
**Signature:**
15631572

website/pages/api-v17/graphql.mdx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ isDevModeEnabled(); // => true
135135

136136
#### GraphQLParseContext
137137

138-
**Interface.** Context published on `graphql:parse`.
138+
**Interface.** Context published on the sync-only `graphql:parse` channel.
139139

140140
<hr className="api-subsection-divider" />
141141

@@ -172,7 +172,7 @@ isDevModeEnabled(); // => true
172172

173173
#### GraphQLValidateContext
174174

175-
**Interface.** Context published on `graphql:validate`.
175+
**Interface.** Context published on the sync-only `graphql:validate` channel.
176176

177177
<hr className="api-subsection-divider" />
178178

@@ -216,6 +216,8 @@ isDevModeEnabled(); // => true
216216

217217
**Interface.** Context published on `graphql:execute`.
218218

219+
Returned results may contain GraphQL errors collected during execution.
220+
219221
<hr className="api-subsection-divider" />
220222

221223
<div className="api-subsection-title">Members</div>
@@ -257,12 +259,12 @@ isDevModeEnabled(); // => true
257259
<tr>
258260
<td>error?</td>
259261
<td><ApiType parts={[["keyword", "unknown"]]} /></td>
260-
<td>Error thrown while executing, when execution fails abruptly.</td>
262+
<td>Error thrown or rejected while executing, when execution fails abruptly.</td>
261263
</tr>
262264
<tr>
263265
<td>result?</td>
264266
<td><ApiType parts={[["link", "ExecutionResult", "/api-v17/execution#executionresult"], " \u007c ", ["link", "ExperimentalIncrementalExecutionResults", "/api-v17/execution#experimentalincrementalexecutionresults"]]} /></td>
265-
<td>Execution result returned by execution.</td>
267+
<td>Execution result returned by execution, including GraphQL errors.</td>
266268
</tr>
267269
</tbody>
268270
</table>
@@ -273,6 +275,8 @@ isDevModeEnabled(); // => true
273275

274276
**Interface.** Context published on `graphql:execute:rootSelectionSet`.
275277

278+
Returned results may contain GraphQL errors collected during execution.
279+
276280
<hr className="api-subsection-divider" />
277281

278282
<div className="api-subsection-title">Members</div>
@@ -319,12 +323,13 @@ isDevModeEnabled(); // => true
319323
<tr>
320324
<td>error?</td>
321325
<td><ApiType parts={[["keyword", "unknown"]]} /></td>
322-
<td>Error thrown while executing the root selection set.</td>
326+
<td>Error thrown or rejected while executing the root selection set.</td>
323327
</tr>
324328
<tr>
325329
<td>result?</td>
326330
<td><ApiType parts={[["link", "ExecutionResult", "/api-v17/execution#executionresult"], " \u007c ", ["link", "ExperimentalIncrementalExecutionResults", "/api-v17/execution#experimentalincrementalexecutionresults"]]} /></td>
327-
<td>Execution result returned from the root selection set.</td>
331+
<td>Execution result returned from the root selection set, including GraphQL<br />
332+
errors.</td>
328333
</tr>
329334
</tbody>
330335
</table>
@@ -335,10 +340,12 @@ isDevModeEnabled(); // => true
335340

336341
**Interface.** Context published on `graphql:execute:variableCoercion`.
337342

338-
Coercion runs synchronously inside argument validation, so only the
339-
`start`/`end` (and, on a thrown error, [`error`](/api-v17/error)) lifecycle fires. When
340-
coercion produces variable errors it does not throw; instead `result`
341-
carries the `errors` array, mirroring `graphql:validate`.
343+
Coercion runs synchronously while execution arguments are validated, so only
344+
the `start`/`end` (and, on an abrupt throw, [`error`](/api-v17/error)) lifecycle fires.
345+
Ordinary variable coercion failures are returned on `result.errors`; when
346+
execution is invoked through APIs such as `execute()` or `subscribe()`, they
347+
surface as GraphQL result errors rather than as the tracing [`error`](/api-v17/error)
348+
lifecycle event.
342349

343350
<hr className="api-subsection-divider" />
344351

@@ -402,6 +409,11 @@ carries the `errors` array, mirroring `graphql:validate`.
402409

403410
**Interface.** Context published on `graphql:subscribe`.
404411

412+
Subscription source resolver errors and invalid source stream results are
413+
returned on `result` as ExecutionResult errors; they do not publish the
414+
[`error`](/api-v17/error) lifecycle event unless subscription setup fails abruptly before
415+
GraphQL can form a result.
416+
405417
<hr className="api-subsection-divider" />
406418

407419
<div className="api-subsection-title">Members</div>
@@ -443,12 +455,13 @@ carries the `errors` array, mirroring `graphql:validate`.
443455
<tr>
444456
<td>error?</td>
445457
<td><ApiType parts={[["keyword", "unknown"]]} /></td>
446-
<td>Error thrown while subscribing, when subscription setup fails abruptly.</td>
458+
<td>Error thrown or rejected while subscribing, when setup fails abruptly.</td>
447459
</tr>
448460
<tr>
449461
<td>result?</td>
450462
<td><ApiType parts={["\u007c ", ["link", "ExecutionResult", "/api-v17/execution#executionresult"], "\n\u007c ", ["type", "AsyncGenerator"], "\u003c", ["link", "ExecutionResult", "/api-v17/execution#executionresult"], ", ", ["keyword", "void"], ", ", ["keyword", "void"], "\u003e"]} /></td>
451-
<td>Subscription response stream or execution result returned by subscribe.</td>
463+
<td>Subscription response stream, or an ExecutionResult containing GraphQL<br />
464+
errors.</td>
452465
</tr>
453466
</tbody>
454467
</table>
@@ -459,6 +472,10 @@ carries the `errors` array, mirroring `graphql:validate`.
459472

460473
**Interface.** Context published on `graphql:resolve`.
461474

475+
Resolver throws and rejections publish the [`error`](/api-v17/error) lifecycle event here.
476+
The same failure may also be formatted into the enclosing execution or
477+
subscription result.
478+
462479
<hr className="api-subsection-divider" />
463480

464481
<div className="api-subsection-title">Members</div>
@@ -510,12 +527,12 @@ carries the `errors` array, mirroring `graphql:validate`.
510527
<tr>
511528
<td>error?</td>
512529
<td><ApiType parts={[["keyword", "unknown"]]} /></td>
513-
<td>Error thrown by the resolver, when resolution fails.</td>
530+
<td>Error thrown or rejected by the resolver, when resolution fails.</td>
514531
</tr>
515532
<tr>
516533
<td>result?</td>
517534
<td><ApiType parts={[["keyword", "unknown"]]} /></td>
518-
<td>Value returned by the resolver.</td>
535+
<td>Value returned by the resolver, when resolution succeeds.</td>
519536
</tr>
520537
</tbody>
521538
</table>
@@ -581,7 +598,7 @@ carries the `errors` array, mirroring `graphql:validate`.
581598

582599
#### GraphQLChannels
583600

584-
**Interface.** The collection of tracing channels graphql-js emits on. Application
601+
**Interface.** The collection of tracing channels GraphQL.js emits on. Application
585602
performance monitoring (APM) tools subscribe to these by name on their own
586603
`node:diagnostics_channel` import; both paths land on the same channel
587604
instance because `tracingChannel(name)` is cached by name.

0 commit comments

Comments
 (0)