Skip to content

Commit f3a30f3

Browse files
committed
Spec edits for incremental delivery, Section 3
1 parent e71805e commit f3a30f3

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
@@ -816,8 +816,8 @@ And will yield the subset of each object type queried:
816816
When querying an Object, the resulting mapping of fields are conceptually
817817
ordered in the same order in which they were encountered during execution,
818818
excluding fragments for which the type does not apply and fields or fragments
819-
that are skipped via `@skip` or `@include` directives. This ordering is
820-
correctly produced when using the {CollectFields()} algorithm.
819+
that are skipped via `@skip` or `@include` directives or postponed via `@defer`.
820+
This ordering is correctly produced when using the {CollectFields()} algorithm.
821821

822822
Response serialization formats capable of representing ordered maps should
823823
maintain this ordering. Serialization formats which can only represent unordered
@@ -1973,6 +1973,14 @@ GraphQL implementations that support the type system definition language must
19731973
provide the `@deprecated` directive if representing deprecated portions of the
19741974
schema.
19751975

1976+
GraphQL implementations may provide the `@defer` and/or `@stream` directives. If
1977+
either or both of these directives are provided, they must conform to the
1978+
requirements defined in this specification.
1979+
1980+
Note: The [Directives Are Defined](#sec-Directives-Are-Defined) validation rule
1981+
ensures that GraphQL Operations containing the `@defer` or `@stream` directives
1982+
cannot be executed by a GraphQL service that does not support them.
1983+
19761984
GraphQL implementations that support the type system definition language should
19771985
provide the `@specifiedBy` directive if representing custom scalar definitions.
19781986

@@ -2190,3 +2198,104 @@ to the relevant IETF specification.
21902198
```graphql example
21912199
scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122")
21922200
```
2201+
2202+
### @defer
2203+
2204+
```graphql
2205+
directive @defer(
2206+
label: String
2207+
if: Boolean! = true
2208+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2209+
```
2210+
2211+
The `@defer` directive may be provided on a fragment spread or inline fragment
2212+
to indicate that execution of the related selection set should be deferred. When
2213+
a request includes the `@defer` directive, the result may consist of multiple
2214+
responses: the initial response containing all non-deferred data, while
2215+
subsequent responses include deferred data.
2216+
2217+
The `@include` and `@skip` directives take precedence over `@defer`.
2218+
2219+
```graphql example
2220+
query myQuery($shouldDefer: Boolean! = true) {
2221+
user {
2222+
name
2223+
...someFragment @defer(label: "someLabel", if: $shouldDefer)
2224+
}
2225+
}
2226+
fragment someFragment on User {
2227+
id
2228+
profile_picture {
2229+
uri
2230+
}
2231+
}
2232+
```
2233+
2234+
#### @defer Arguments
2235+
2236+
- `if: Boolean! = true` - When `true`, fragment _should_ be deferred (see
2237+
related note below). When `false`, fragment must not be deferred. Defaults to
2238+
`true` when omitted.
2239+
- `label: String` - An optional string literal (variables are disallowed) used
2240+
by GraphQL clients to identify data from responses and associate it with the
2241+
corresponding defer directive. If provided, the GraphQL service must include
2242+
this label in the corresponding pending object within the response. The
2243+
`label` argument must be unique across all `@defer` and `@stream` directives
2244+
in the document.
2245+
2246+
### @stream
2247+
2248+
```graphql
2249+
directive @stream(
2250+
label: String
2251+
if: Boolean! = true
2252+
initialCount: Int = 0
2253+
) on FIELD
2254+
```
2255+
2256+
The `@stream` directive may be provided for a field whose type incorporates a
2257+
`List` type modifier; the directive enables the backend to leverage technology
2258+
such as asynchronous iterators to provide a partial list initially, and
2259+
additional list items in subsequent responses.
2260+
2261+
The `@include` and `@skip` directives take precedence over `@stream`.
2262+
2263+
```graphql example
2264+
query myQuery($shouldStream: Boolean! = true) {
2265+
user {
2266+
friends(first: 10) {
2267+
nodes
2268+
@stream(label: "friendsStream", initialCount: 5, if: $shouldStream) {
2269+
name
2270+
}
2271+
}
2272+
}
2273+
}
2274+
```
2275+
2276+
#### @stream Arguments
2277+
2278+
- `if: Boolean! = true` - When `true`, field _should_ be streamed (see related
2279+
note below). When `false`, the field must not be streamed and all list items
2280+
must be initially included. Defaults to `true` when omitted.
2281+
- `label: String` - An optional string literal (variables are disallowed) used
2282+
by GraphQL clients to identify data from responses and associate it with the
2283+
corresponding stream directive. If provided, the GraphQL service must include
2284+
this label in the corresponding pending object within the result. The `label`
2285+
argument must be unique across all `@defer` and `@stream` directives in the
2286+
document.
2287+
- `initialCount: Int` - The number of list items the service should return
2288+
initially. If omitted, defaults to `0`. A field error will be raised if the
2289+
value of this argument is less than `0`.
2290+
2291+
Note: The ability to defer and/or stream parts of a response can have a
2292+
potentially significant impact on application performance. Developers generally
2293+
need clear, predictable control over their application's performance. It is
2294+
highly recommended that GraphQL services honor the `@defer` and `@stream`
2295+
directives on each execution. However, the specification allows advanced use
2296+
cases where the service can determine that it is more performant to not defer
2297+
and/or stream. Therefore, GraphQL clients _must_ be able to process a response
2298+
that ignores the `@defer` and/or `@stream` directives. This also applies to the
2299+
`initialCount` argument on the `@stream` directive. Clients _must_ be able to
2300+
process a streamed response that contains a different number of initial list
2301+
items than what was specified in the `initialCount` argument.

0 commit comments

Comments
 (0)