-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Spec edits for incremental delivery, Section 3 only #1132
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
8
commits into
incremental-integration
Choose a base branch
from
incremental-integration-type-system
base: incremental-integration
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
8 commits
Select commit
Hold shift + click to select a range
f3a30f3
Spec edits for incremental delivery, Section 3
robrichard e7cfcf0
re-order arguments
robrichard df61253
Apply suggestions from code review
robrichard 96caa27
Address PR feedback
robrichard ebd7061
Address PR feedback
robrichard f1abaac
Update spec/Section 3 -- Type System.md
robrichard 6df7b50
Update response terminology
robrichard 64dc38f
Use new execution result terminology
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,8 +816,8 @@ And will yield the subset of each object type queried: | |
When querying an Object, the resulting mapping of fields are conceptually | ||
ordered in the same order in which they were encountered during execution, | ||
excluding fragments for which the type does not apply and fields or fragments | ||
that are skipped via `@skip` or `@include` directives. This ordering is | ||
correctly produced when using the {CollectFields()} algorithm. | ||
that are skipped via `@skip` or `@include` directives or postponed via `@defer`. | ||
This ordering is correctly produced when using the {CollectFields()} algorithm. | ||
|
||
Response serialization formats capable of representing ordered maps should | ||
maintain this ordering. Serialization formats which can only represent unordered | ||
|
@@ -1973,6 +1973,15 @@ GraphQL implementations that support the type system definition language must | |
provide the `@deprecated` directive if representing deprecated portions of the | ||
schema. | ||
|
||
GraphQL implementations may provide the `@defer` and/or `@stream` directives. If | ||
either or both of these directives are provided, they must conform to the | ||
requirements defined in this specification. | ||
|
||
Note: The [Directives Are Defined](#sec-Directives-Are-Defined) validation rule | ||
ensures that GraphQL operations can only include directives available on the | ||
schema; thus operations including `@defer` or `@stream` directives can only be | ||
executed by a GraphQL service that supports them. | ||
|
||
GraphQL implementations that support the type system definition language should | ||
provide the `@specifiedBy` directive if representing custom scalar definitions. | ||
|
||
|
@@ -2190,3 +2199,117 @@ to the relevant IETF specification. | |
```graphql example | ||
scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122") | ||
``` | ||
|
||
### @defer | ||
|
||
```graphql | ||
directive @defer( | ||
if: Boolean! = true | ||
label: String | ||
) on FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
``` | ||
|
||
The `@defer` directive may be provided on a fragment spread or inline fragment | ||
to indicate that execution of the related selection set should be deferred. When | ||
a request includes the `@defer` directive, it may return an _incremental stream_ | ||
consisting of an _initial execution result_ containing all non-deferred data, | ||
followed by one or more _subsequent execution result_ including the deferred | ||
data. | ||
|
||
The `@include` and `@skip` directives take precedence over `@defer`. | ||
|
||
```graphql example | ||
query myQuery($shouldDefer: Boolean! = true) { | ||
user { | ||
name | ||
...someFragment @defer(label: "someLabel", if: $shouldDefer) | ||
} | ||
} | ||
fragment someFragment on User { | ||
id | ||
profile_picture { | ||
uri | ||
} | ||
} | ||
``` | ||
|
||
#### @defer Arguments | ||
|
||
- `if: Boolean! = true` - When `true`, fragment _should_ be deferred (see | ||
related note below). When `false`, fragment must not be deferred. Defaults to | ||
`true` when omitted. | ||
- `label: String` - An optional string literal (variables are disallowed) used | ||
by GraphQL clients to identify data in the _incremental stream_ and associate | ||
it with the corresponding defer directive. If provided, the GraphQL service | ||
must include this label in the corresponding pending object within the | ||
_incremental stream_. The `label` argument must be unique across all `@defer` | ||
and `@stream` directives in the document. | ||
|
||
### @stream | ||
|
||
```graphql | ||
directive @stream( | ||
initialCount: Int! = 0 | ||
if: Boolean! = true | ||
label: String | ||
) on FIELD | ||
``` | ||
|
||
The `@stream` directive may be provided for a field whose type incorporates a | ||
`List` type modifier. The directive enables returning a partial list initially, | ||
followed by additional items in one or more _subsequent execution result_. If | ||
the field type incorporates multiple `List` type modifiers, only the outermost | ||
list is streamed. | ||
|
||
Note: The mechanism through which items are streamed is implementation-defined | ||
and may use technologies such as asynchronous iterators. | ||
|
||
The `@include` and `@skip` directives take precedence over `@stream`. | ||
|
||
```graphql example | ||
query myQuery($shouldStream: Boolean! = true) { | ||
user { | ||
friends(first: 10) | ||
@stream(label: "friendsStream", initialCount: 5, if: $shouldStream) { | ||
name | ||
} | ||
} | ||
} | ||
``` | ||
|
||
#### @stream Arguments | ||
|
||
- `initialCount: Int! = 0` - The number of list items to include initially when | ||
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. should this arg be last? to match if/label/* order from defer |
||
completing the parent selection set. If omitted, defaults to `0`. A field | ||
error will be raised if the value of this argument is less than `0`. When the | ||
size of the list is greater than or equal to the value of `initialCount`, the | ||
GraphQL service _must_ initially include at least as many list items as the | ||
value of `initialCount` (see related note below). | ||
- `if: Boolean! = true` - When `true`, field _should_ be streamed (see related | ||
note below). When `false`, the field must behave as if the `@stream` directive | ||
is not present—it must not be streamed and all of the list items must be | ||
included. Defaults to `true` when omitted. | ||
- `label: String` - An optional string literal (variables are disallowed) used | ||
by GraphQL clients to identify data in the _incremental stream_ and associate | ||
it with the corresponding stream directive. If provided, the GraphQL service | ||
must include this label in the corresponding pending object within the | ||
_incremental stream_. The `label` argument must be unique across all `@defer` | ||
and `@stream` directives in the document. | ||
|
||
Note: The | ||
[Defer And Stream Directive Labels Are Unique](#sec-Defer-And-Stream-Directive-Labels-Are-Unique) | ||
validation rule ensures uniqueness of the values passed to `label` on both the | ||
`@defer` and `@stream` directives. Variables are disallowed in the `label` | ||
because their values may not be known during validation. | ||
|
||
Note: The ability to defer and/or stream data can have a potentially significant | ||
impact on application performance. Developers generally need clear, predictable | ||
control over their application's performance. It is highly recommended that | ||
GraphQL services honor the `@defer` and `@stream` directives on each execution. | ||
However, the specification allows advanced use cases where the service can | ||
determine that it is more performant to not defer and/or stream. Therefore, | ||
GraphQL clients _must_ be able to process a _response_ that ignores individual | ||
`@defer` and/or `@stream` directives. This also applies to the `initialCount` | ||
argument on the `@stream` directive. Clients must be able to process a streamed | ||
field result that contains more initial list items than what was specified in | ||
the `initialCount` argument. |
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.
keep
if
consistently as the first arg