Skip to content

Commit a5a488c

Browse files
committed
Spec edits for incremental delivery, Section 3
1 parent 96271da commit a5a488c

File tree

1 file changed

+111
-2
lines changed

1 file changed

+111
-2
lines changed

spec/Section 3 -- Type System.md

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,8 @@ And will yield the subset of each object type queried:
812812
When querying an Object, the resulting mapping of fields are conceptually
813813
ordered in the same order in which they were encountered during execution,
814814
excluding fragments for which the type does not apply and fields or fragments
815-
that are skipped via `@skip` or `@include` directives. This ordering is
816-
correctly produced when using the {CollectFields()} algorithm.
815+
that are skipped via `@skip` or `@include` directives or postponed via `@defer`.
816+
This ordering is correctly produced when using the {CollectFields()} algorithm.
817817

818818
Response serialization formats capable of representing ordered maps should
819819
maintain this ordering. Serialization formats which can only represent unordered
@@ -2084,6 +2084,14 @@ GraphQL implementations that support the type system definition language must
20842084
provide the `@deprecated` directive if representing deprecated portions of the
20852085
schema.
20862086

2087+
GraphQL implementations may provide the `@defer` and/or `@stream` directives. If
2088+
either or both of these directives are provided, they must conform to the
2089+
requirements defined in this specification.
2090+
2091+
Note: The [Directives Are Defined](#sec-Directives-Are-Defined) validation rule
2092+
ensures that GraphQL Operations containing the `@defer` or `@stream` directives
2093+
cannot be executed by a GraphQL service that does not support them.
2094+
20872095
GraphQL implementations that support the type system definition language should
20882096
provide the `@specifiedBy` directive if representing custom scalar definitions.
20892097

@@ -2321,3 +2329,104 @@ input UserUniqueCondition @oneOf {
23212329
organizationAndEmail: OrganizationAndEmailInput
23222330
}
23232331
```
2332+
2333+
### @defer
2334+
2335+
```graphql
2336+
directive @defer(
2337+
label: String
2338+
if: Boolean! = true
2339+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2340+
```
2341+
2342+
The `@defer` directive may be provided on a fragment spread or inline fragment
2343+
to indicate that execution of the related selection set should be deferred. When
2344+
a request includes the `@defer` directive, the result may consist of multiple
2345+
responses: the initial response containing all non-deferred data, while
2346+
subsequent responses include deferred data.
2347+
2348+
The `@include` and `@skip` directives take precedence over `@defer`.
2349+
2350+
```graphql example
2351+
query myQuery($shouldDefer: Boolean! = true) {
2352+
user {
2353+
name
2354+
...someFragment @defer(label: "someLabel", if: $shouldDefer)
2355+
}
2356+
}
2357+
fragment someFragment on User {
2358+
id
2359+
profile_picture {
2360+
uri
2361+
}
2362+
}
2363+
```
2364+
2365+
#### @defer Arguments
2366+
2367+
- `if: Boolean! = true` - When `true`, fragment _should_ be deferred (see
2368+
related note below). When `false`, fragment must not be deferred. Defaults to
2369+
`true` when omitted.
2370+
- `label: String` - An optional string literal (variables are disallowed) used
2371+
by GraphQL clients to identify data from responses and associate it with the
2372+
corresponding defer directive. If provided, the GraphQL service must include
2373+
this label in the corresponding pending object within the response. The
2374+
`label` argument must be unique across all `@defer` and `@stream` directives
2375+
in the document.
2376+
2377+
### @stream
2378+
2379+
```graphql
2380+
directive @stream(
2381+
label: String
2382+
if: Boolean! = true
2383+
initialCount: Int = 0
2384+
) on FIELD
2385+
```
2386+
2387+
The `@stream` directive may be provided for a field whose type incorporates a
2388+
`List` type modifier; the directive enables the backend to leverage technology
2389+
such as asynchronous iterators to provide a partial list initially, and
2390+
additional list items in subsequent responses.
2391+
2392+
The `@include` and `@skip` directives take precedence over `@stream`.
2393+
2394+
```graphql example
2395+
query myQuery($shouldStream: Boolean! = true) {
2396+
user {
2397+
friends(first: 10) {
2398+
nodes
2399+
@stream(label: "friendsStream", initialCount: 5, if: $shouldStream) {
2400+
name
2401+
}
2402+
}
2403+
}
2404+
}
2405+
```
2406+
2407+
#### @stream Arguments
2408+
2409+
- `if: Boolean! = true` - When `true`, field _should_ be streamed (see related
2410+
note below). When `false`, the field must not be streamed and all list items
2411+
must be initially included. Defaults to `true` when omitted.
2412+
- `label: String` - An optional string literal (variables are disallowed) used
2413+
by GraphQL clients to identify data from responses and associate it with the
2414+
corresponding stream directive. If provided, the GraphQL service must include
2415+
this label in the corresponding pending object within the result. The `label`
2416+
argument must be unique across all `@defer` and `@stream` directives in the
2417+
document.
2418+
- `initialCount: Int` - The number of list items the service should return
2419+
initially. If omitted, defaults to `0`. A field error will be raised if the
2420+
value of this argument is less than `0`.
2421+
2422+
Note: The ability to defer and/or stream parts of a response can have a
2423+
potentially significant impact on application performance. Developers generally
2424+
need clear, predictable control over their application's performance. It is
2425+
highly recommended that GraphQL services honor the `@defer` and `@stream`
2426+
directives on each execution. However, the specification allows advanced use
2427+
cases where the service can determine that it is more performant to not defer
2428+
and/or stream. Therefore, GraphQL clients _must_ be able to process a response
2429+
that ignores the `@defer` and/or `@stream` directives. This also applies to the
2430+
`initialCount` argument on the `@stream` directive. Clients _must_ be able to
2431+
process a streamed response that contains a different number of initial list
2432+
items than what was specified in the `initialCount` argument.

0 commit comments

Comments
 (0)