Skip to content

Commit 31c90e7

Browse files
committed
Detail onError request parameter
1 parent dc7b27e commit 31c90e7

File tree

1 file changed

+83
-21
lines changed

1 file changed

+83
-21
lines changed

spec/Section 6 -- Execution.md

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ A GraphQL service generates a response from a request via execution.
44

55
:: A _request_ for execution consists of a few pieces of information:
66

7+
<!-- https://github.com/prettier/prettier/issues/17286 -->
8+
<!-- prettier-ignore -->
79
- {schema}: The schema to use, typically solely provided by the GraphQL service.
810
- {document}: A {Document} which must contain GraphQL {OperationDefinition} and
911
may contain {FragmentDefinition}.
@@ -15,13 +17,23 @@ A GraphQL service generates a response from a request via execution.
1517
being executed. Conceptually, an initial value represents the "universe" of
1618
data available via a GraphQL Service. It is common for a GraphQL Service to
1719
always use the same initial value for every request.
20+
- {onError} (optional): The _error behavior_ to apply to the request; see
21+
[Handling Execution Errors](#sec-Handling-Execution-Errors). If {onError} is
22+
provided and its value is not one of {"PROPAGATE"}, {"NO_PROPAGATE"}, or
23+
{"ABORT"}, then a _request error_ must be raised.
1824
- {extensions} (optional): A map reserved for implementation-specific additional
1925
information.
2026

2127
Given this information, the result of {ExecuteRequest(schema, document,
2228
operationName, variableValues, initialValue)} produces the response, to be
2329
formatted according to the Response section below.
2430

31+
Note: Previous versions of this specification did not define the {onError}
32+
request attribute. Clients can detect support for {onError} by checking for the
33+
presence of the `defaultErrorBehavior` field on the `__Schema` introspection
34+
type. If this field is absent, clients should not include {onError} in the
35+
request and must assume the _error behavior_ is {"PROPAGATE"}.
36+
2537
Implementations should not add additional properties to a _request_, which may
2638
conflict with future editions of the GraphQL specification. Instead,
2739
{extensions} provides a reserved location for implementation-specific additional
@@ -392,13 +404,24 @@ is explained in greater detail in the Field Collection section below.
392404
</a>
393405

394406
If during {ExecuteSelectionSet()} a _response position_ with a non-null type
395-
raises an _execution error_ then that error must propagate to the parent
396-
response position (the entire selection set in the case of a field, or the
397-
entire list in the case of a list position), either resolving to {null} if
398-
allowed or being further propagated to a parent response position.
399-
400-
If this occurs, any sibling response positions which have not yet executed or
401-
have not yet yielded a value may be cancelled to avoid unnecessary work.
407+
raises an _execution error_, the error must be added to the {"errors"} list in
408+
the _response_ and then handled according to the _error behavior_ of the
409+
request:
410+
411+
<!-- https://github.com/prettier/prettier/issues/17286 -->
412+
<!-- prettier-ignore -->
413+
- {"NO\_PROPAGATE"}: The _response position_ must be set to {null}. (The client
414+
is responsible for interpreting this {null} in conjunction with the {"errors"}
415+
list to distinguish error results from intentional {null} values.)
416+
- {"PROPAGATE"}: The _execution error_ must propagate to the parent _response
417+
position_ (the entire selection set in the case of a field, or the entire list
418+
in the case of a list position). The parent position resolves to {null} if
419+
allowed, or else the error is further propagated to a parent response
420+
position. Any sibling response positions that have not yet executed or have
421+
not yet yielded a value may be cancelled to avoid unnecessary work.
422+
- {"ABORT"}: The entire _request_ must be aborted. The {"data"} entry in the
423+
_response_ must be {null}. Any _response position_ that has not yet executed
424+
or has not yet yielded a value may be cancelled to avoid unnecessary work.
402425

403426
Note: See [Handling Execution Errors](#sec-Handling-Execution-Errors) for more
404427
about this behavior.
@@ -823,28 +846,61 @@ MergeSelectionSets(fields):
823846
</a>
824847

825848
An _execution error_ is an error raised during field execution, value resolution
826-
or coercion, at a specific _response position_. While these errors must be
827-
reported in the response, they are "handled" by producing partial {"data"} in
828-
the _response_.
849+
or coercion, at a specific _response position_. These errors must be added to
850+
the {"errors"} list in the _response_, and are "handled" according to the _error
851+
behavior_ of the request.
852+
853+
Note: An _execution error_ is distinct from a _request error_ which results in a
854+
response with no {"data"}.
855+
856+
If a _response position_ resolves to {null} because of an execution error which
857+
has already been added to the {"errors"} list in the response, the {"errors"}
858+
list must not be further affected. That is, only one error should be added to
859+
the errors list per _response position_.
860+
861+
:: The _error behavior_ of a request indicates how an _execution error_ is
862+
handled. It may be specified using the optional {onError} attribute of the
863+
_request_. If omitted, the _default error behavior_ of the schema applies. Valid
864+
values for _error behavior_ are {"PROPAGATE"}, {"NO_PROPAGATE"} and {"ABORT"}.
865+
866+
:: The _default error behavior_ of a schema is implementation-defined. For
867+
compatibility with existing clients, schemas should default to {"PROPAGATE"}
868+
which reflects prior behavior. For new schemas, {"NO_PROPAGATE"} is recommended.
869+
The default error behavior is indicated via the `defaultErrorBehavior` field of
870+
the `__Schema` introspection type, or via the `@behavior` schema directive.
871+
872+
Note: {"ABORT"} is not recommended as the _default error behavior_ because it
873+
prevents generating partial responses which may still contain useful data.
874+
875+
Regardless of error behavior, if a _response position_ with a non-null type
876+
results in {null} due to the result of {ResolveFieldValue()} then an execution
877+
error must be raised at that position as specified in {CompleteValue()}.
829878

830-
Note: This is distinct from a _request error_ which results in a response with
831-
no data.
879+
The _error behavior_ of a request applies to every _execution error_ raised
880+
during execution. The following sections describe the behavior of each valid
881+
value:
832882

833-
If an execution error is raised while resolving a field (either directly or
834-
nested inside any lists), it is handled as though the _response position_ at
835-
which the error occurred resolved to {null}, and the error must be added to the
836-
{"errors"} list in the response.
883+
**{"NO_PROPAGATE"}**
884+
885+
<!-- https://github.com/prettier/prettier/issues/17286 -->
886+
<!-- prettier-ignore -->
887+
With {"NO\_PROPAGATE"}, a `Non-Null` _response position_ will have the value
888+
{null} if and only if an error occurred at that position.
889+
890+
Note: Clients must inspect the {"errors"} list and use the {"path"} of each
891+
error result to distinguish between intentional {null} values and those
892+
resulting from an _execution error_.
893+
894+
**{"PROPAGATE"}**
895+
896+
With {"PROPAGATE"}, a `Non-Null` _response position_ must not contain {null} in
897+
the _response_.
837898

838899
If the result of resolving a _response position_ is {null} (either due to the
839900
result of {ResolveFieldValue()} or because an execution error was raised), and
840901
that position is of a `Non-Null` type, then an execution error is raised at that
841902
position. The error must be added to the {"errors"} list in the response.
842903

843-
If a _response position_ resolves to {null} because of an execution error which
844-
has already been added to the {"errors"} list in the response, the {"errors"}
845-
list must not be further affected. That is, only one error should be added to
846-
the errors list per _response position_.
847-
848904
Since `Non-Null` response positions cannot be {null}, execution errors are
849905
propagated to be handled by the parent _response position_. If the parent
850906
response position may be {null} then it resolves to {null}, otherwise if it is a
@@ -859,3 +915,9 @@ position_ must resolve to {null}. If the `List` type is also wrapped in a
859915
If every _response position_ from the root of the request to the source of the
860916
execution error has a `Non-Null` type, then the {"data"} entry in the response
861917
should be {null}.
918+
919+
**{"ABORT"}**
920+
921+
With {"ABORT"}, execution must cease immediately when the first _execution
922+
error_ is raised. That error must be added to the {"errors"} list, and {"data"}
923+
must be {null}.

0 commit comments

Comments
 (0)