-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Define "execution result" and "request error result" #1159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robrichard
wants to merge
5
commits into
main
Choose a base branch
from
robrichard/response
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dbb9c6
Define "execution result" and "request error result"
robrichard fa4358e
address PR comments
robrichard 3d92858
fix errors
robrichard a93f61a
Apply suggestions from code review
robrichard a13ec36
Use updated wording for request error
robrichard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,40 +9,66 @@ the case that any _execution error_ was raised and replaced with {null}. | |
|
||
## Response Format | ||
|
||
A GraphQL request returns either a _response_ or a _response stream_. | ||
:: A GraphQL request returns a _response_. A _response_ is either an _execution | ||
result_, a _response stream_, or a _request error result_. | ||
|
||
### Response | ||
### Execution Result | ||
|
||
:: A GraphQL request returns a _response_ when the GraphQL operation is a query | ||
or mutation. A _response_ must be a map. | ||
:: A GraphQL request returns an _execution result_ when the GraphQL operation is | ||
a query or mutation and the request included execution. Additionally, for each | ||
event in a subscription's _source stream_, the _response stream_ will emit an | ||
_execution result_. | ||
|
||
If the request raised any errors, the response map must contain an entry with | ||
key {"errors"}. The value of this entry is described in the "Errors" section. If | ||
the request completed without raising any errors, this entry must not be | ||
present. | ||
An _execution result_ must be map. | ||
|
||
If the request included execution, the response map must contain an entry with | ||
key {"data"}. The value of this entry is described in the "Data" section. If the | ||
request failed before execution, due to a syntax error, missing information, or | ||
validation error, this entry must not be present. | ||
The _execution result_ must contain an entry with key {"data"}. The value of | ||
this entry is described in the "Data" section. | ||
|
||
The response map may also contain an entry with key `extensions`. This entry, if | ||
set, must have a map as its value. This entry is reserved for implementers to | ||
extend the protocol however they see fit, and hence there are no additional | ||
restrictions on its contents. | ||
If execution raised any errors, the _execution result_ must contain an entry | ||
with key {"errors"}. The value of this entry must be a non-empty list of | ||
_execution error_ raised during execution. Each error must be a map as described | ||
in the "Errors" section below. If the request completed without raising any | ||
errors, this entry must not be present. | ||
|
||
To ensure future changes to the protocol do not break existing services and | ||
clients, the top level response map must not contain any entries other than the | ||
three described above. | ||
Note: When {"errors"} is present in a _execution result_, it may be helpful for | ||
it to appear first when serialized to make it more apparent that errors are | ||
present. | ||
|
||
Note: When {"errors"} is present in the response, it may be helpful for it to | ||
appear first when serialized to make it more clear when errors are present in a | ||
response during debugging. | ||
The _execution result_ may also contain an entry with key `extensions`. The | ||
value of this entry is described in the "Extensions" section. | ||
|
||
### Response Stream | ||
|
||
:: A GraphQL request returns a _response stream_ when the GraphQL operation is a | ||
subscription. A _response stream_ must be a stream of _response_. | ||
subscription and the request included execution. A response stream must be a | ||
stream of _execution result_. | ||
|
||
### Request Error Result | ||
|
||
:: A GraphQL request returns a _request error result_ when one or more _request | ||
error_ are raised, causing the request to fail before execution. This request | ||
will result in no response data. | ||
|
||
Note: A _request error_ may be raised before execution due to missing | ||
information, syntax errors, validation failure, coercion failure, or any other | ||
reason the implementation may determine should prevent the request from | ||
proceeding. | ||
|
||
A _request error result_ must be a map. | ||
|
||
The _request error result_ map must contain an entry with key {"errors"}. The | ||
value of this entry must be a non-empty list of _request error_ raised during | ||
the _request_. It must contain at least one _request error_ indicating why no | ||
data was able to be returned. Each error must be a map as described in the | ||
"Errors" section below. | ||
|
||
Note: It may be helpful for the {"errors"} key to appear first when serialized | ||
to make it more apparent that errors are present. | ||
robrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The _request error result_ map must not contain an entry with key {"data"}. | ||
|
||
The _request error result_ map may also contain an entry with key `extensions`. | ||
The value of this entry is described in the "Extensions" section. | ||
|
||
### Response Position | ||
|
||
|
@@ -89,37 +115,25 @@ found at `["hero", "friends"]`, the hero's first friend at | |
|
||
### Data | ||
|
||
The {"data"} entry in the response will be the result of the execution of the | ||
requested operation. If the operation was a query, this output will be an object | ||
of the query root operation type; if the operation was a mutation, this output | ||
will be an object of the mutation root operation type. | ||
The {"data"} entry in the _execution result_ will be the result of the execution | ||
of the requested operation. If the operation was a query, this output will be an | ||
object of the query root operation type; if the operation was a mutation, this | ||
output will be an object of the mutation root operation type. | ||
|
||
The response data is the result of accumulating the resolved result of all | ||
response positions during execution. | ||
|
||
If an error was raised before execution begins, the {"data"} entry should not be | ||
present in the response. | ||
If an error was raised before execution begins, the _response_ must be a | ||
_request error result_ which will result in no response data. | ||
|
||
If an error was raised during the execution that prevented a valid response, the | ||
{"data"} entry in the response should be `null`. | ||
|
||
### Errors | ||
|
||
The {"errors"} entry in the response is a non-empty list of errors raised during | ||
the _request_, where each error is a map of data described by the error result | ||
format below. | ||
|
||
If present, the {"errors"} entry in the response must contain at least one | ||
error. If no errors were raised during the request, the {"errors"} entry must | ||
not be present in the response. | ||
|
||
If the {"data"} entry in the response is not present, the {"errors"} entry must | ||
be present. It must contain at least one _request error_ indicating why no data | ||
was able to be returned. | ||
|
||
If the {"data"} entry in the response is present (including if it is the value | ||
{null}), the {"errors"} entry must be present if and only if one or more | ||
_execution error_ was raised during execution. | ||
The {"errors"} entry in the _execution result_ or _request error result_ is a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also define a type Response Result that includes both Execution Result and Request Error Result as subtypes, but adding another layer of hierarchy might be less clear? |
||
non-empty list of errors raised during the _request_, where each error is a map | ||
of data described by the error result format below. | ||
|
||
**Request Errors** | ||
|
||
|
@@ -130,9 +144,9 @@ to determine which operation to execute, or invalid input values for variables. | |
|
||
A request error is typically the fault of the requesting client. | ||
|
||
If a request error is raised, the {"data"} entry in the response must not be | ||
present, the {"errors"} entry must include the error, and request execution | ||
should be halted. | ||
If a request error is raised, the _response_ must be a _request error result_. | ||
The {"data"} entry in this map must not be present, the {"errors"} entry must | ||
include the error, and request execution should be halted. | ||
|
||
**Execution Errors** | ||
|
||
|
@@ -307,6 +321,20 @@ discouraged. | |
} | ||
``` | ||
|
||
### Extensions | ||
|
||
The {"extensions"} entry in an _execution result_ or _request error result_, if | ||
set, must have a map as its value. This entry is reserved for implementers to | ||
extend the protocol however they see fit, and hence there are no additional | ||
restrictions on its contents. | ||
|
||
### Additional Entries | ||
|
||
To ensure future changes to the protocol do not break existing services and | ||
clients, the _execution result_ and _request error result_ maps must not contain | ||
any entries other than those described above. Clients must ignore any entries | ||
other than those described above. | ||
|
||
## Serialization Format | ||
|
||
GraphQL does not require a specific serialization format. However, clients | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved and adjusted some of the text from the Errors section. Placing it under
Execution Result
andRequest Error Result
so we can describe the specific behavior (must be included inRequest Error Result
, may be included inExecution Result
) without the Errors section having conditions for each type.