Skip to content

Commit

Permalink
Introduce @defer and @stream.
Browse files Browse the repository at this point in the history
Update Section 3 -- Type System.md

Update Section 3 -- Type System.md

Update Section 3 -- Type System.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Update Section 6 -- Execution.md

Amend changes
  • Loading branch information
Keweiqu authored and robrichard committed Jun 23, 2020
1 parent 05d4a3b commit 00a6556
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 28 deletions.
52 changes: 49 additions & 3 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,9 @@ 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 query 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.
fragments that are skipped via `@skip` or `@include` directives or temporarily
skipped 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
Expand Down Expand Up @@ -1752,7 +1753,7 @@ A GraphQL schema describes directives which are used to annotate various parts
of a GraphQL document as an indicator that they should be evaluated differently
by a validator, executor, or client tool such as a code generator.

GraphQL implementations should provide the `@skip` and `@include` directives.
GraphQL implementations should provide the `@skip`, `@include`, `@defer` and `@stream` directives.

GraphQL implementations that support the type system definition language must
provide the `@deprecated` directive if representing deprecated portions of
Expand Down Expand Up @@ -1920,3 +1921,48 @@ type ExampleType {
oldField: String @deprecated(reason: "Use `newField`.")
}
```

### @defer
```graphql
directive @defer(label: String!, if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT
```
The `@defer` directive may be provided for fragment spreads and inline fragments to
inform the executor to delay the execution of the current fragment to indicate
deprioritization of the current fragment. A query with `@defer` directive will cause
the request to potentially return multiple responses, where non-deferred data is
delivered in the initial response and data deferred delivered in a subsequent response.
`@include` and `@skip` take presedence over `@defer`.

```graphql example
query myQuery($shouldDefer: Boolean) {
user {
name
...someFragment @defer(label: 'someLabel', if: $shouldDefer)
}
}
fragment someFragment on User {
id
profile_picture {
uri
}
}
```

### @stream
```graphql
directive @stream(label: String!, initial_count: Int!, if: Boolean) on FIELD
```
The `@stream` directive may be provided for a field of `List` type so that the
backend can leverage technology such asynchronous iterators to provide a partial
list in the initial response, and additional list items in subsequent responses.
`@include` and `@skip` take presedence over `@stream`.
```graphql example
query myQuery($shouldDefer: Boolean) {
user {
friends(first: 10) {
nodes @stream(label: "friendsStream", initial_count: 5)
}
}
}

```
Loading

0 comments on commit 00a6556

Please sign in to comment.