Skip to content

Commit ec27a72

Browse files
authored
Merge pull request #36 from apollographql/nullability
Add nullability directives
2 parents 392e61a + 639ab1f commit ec27a72

File tree

4 files changed

+111
-6
lines changed

4 files changed

+111
-6
lines changed

__index__.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
- **[join/v0.1](/join/v0.1)** ([📄 graphql](join/v0.1/join-v0.1.graphql))
1212
- **[join/v0.2](/join/v0.2)** ([📄 graphql](join/v0.2/join-v0.2.graphql))
1313
- **[join/v0.3](/join/v0.3)** ([📄 graphql](join/v0.3/join-v0.3.graphql))
14+
- **[kotlin_labs/v0.1](/kotlin_labs/v0.1)** ([📄 graphql](kotlin_labs/v0.1/kotlin_labs-v0.1.graphql))
15+
- **[kotlin_labs/v0.2](/kotlin_labs/v0.2)** ([📄 graphql](kotlin_labs/v0.2/kotlin_labs-v0.2.graphql))
1416
- **[link/v1.0](/link/v1.0)** ([📄 graphql](link/v1.0/link-v1.0.graphql))
17+
- **[nullability/v0.1](/nullability/v0.1)** ([📄 graphql](nullability/v0.1/nullability-v0.1.graphql))
1518
- **[tag/v0.1](/tag/v0.1)** ([📄 graphql](tag/v0.1/tag-v0.1.graphql))
1619
- **[tag/v0.2](/tag/v0.2)** ([📄 graphql](tag/v0.2/tag-v0.2.graphql))
17-
- **[kotlin_labs/v0.1](/kotlin_labs/v0.1)** ([📄 graphql](kotlin_labs/v0.1/kotlin_labs-v0.1.graphql))
18-
- **[kotlin_labs/v0.2](/kotlin_labs/v0.2)** ([📄 graphql](kotlin_labs/v0.2/kotlin_labs-v0.2.graphql))

index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131

3232
[inaccessible v0.2](inaccessible/v0.2) masks fields and types from a graph's public API
3333

34-
## kotlin_labs v0.1
35-
36-
[kotlin_labs v0.1](kotlin_labs/v0.1) incubating directives supported by the Apollo Kotlin client
37-
3834
## kotlin_labs v0.2
3935

4036
[kotlin_labs v0.2](kotlin_labs/v0.2) incubating directives supported by the Apollo Kotlin client
4137

38+
## nullability v0.1
39+
40+
[nullability v0.1](nullability/v0.1) incubating directives to work with nullability
41+
4242
# All Schemas
4343

4444
Everything in this library:
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Indicates that a field is only null if there is a matching error in the `errors` array.
3+
In all other cases, the field is non-null.
4+
5+
Tools doing code generation may use this information to generate the field as non-null.
6+
7+
This directive can be applied on field definitions:
8+
9+
```graphql
10+
type User {
11+
email: String @semanticNonNull
12+
}
13+
```
14+
15+
It can also be applied on object type extensions for use in client applications that do
16+
not own the base schema:
17+
18+
```graphql
19+
extend type User @semanticNonNull(field: "email")
20+
```
21+
22+
Control over list items is done using the `level` argument:
23+
24+
```graphql
25+
type User {
26+
# friends is nullable but friends[0] is null only on errors
27+
friends: [User] @semanticNonNull(level: 1)
28+
}
29+
```
30+
31+
The `field` argument is the name of the field if `@semanticNonNull` is applied to an object definition.
32+
If `@semanticNonNull` is applied to a field definition, `field` must be null.
33+
34+
The `level` argument can be used to indicate what level is semantically non null in case of lists.
35+
`level` starts at 0 if there is no list. If `level` is null, all levels are semantically non null.
36+
"""
37+
directive @semanticNonNull(field: String = null, level: Int = null) repeatable on FIELD_DEFINITION | OBJECT
38+
39+
"""
40+
Indicates how clients should handle errors on a given position.
41+
42+
When used on the schema definition, `@catch` applies to every position that can return an error.
43+
44+
The `level` argument can be used to indicate where to catch in case of lists.
45+
`level` starts at 0 if there is no list. If `level` is null, all levels catch.
46+
47+
See `CatchTo` for more details.
48+
"""
49+
directive @catch(to: CatchTo! = RESULT, level: Int = null) repeatable on FIELD | SCHEMA
50+
51+
enum CatchTo {
52+
"""
53+
Catch the error and map the position to a result type that can contain either
54+
a value or an error.
55+
"""
56+
RESULT,
57+
"""
58+
Catch the error and map the position to a nullable type that will be null
59+
in the case of error.
60+
This does not allow to distinguish between semantic null and error null but
61+
can be simpler in some cases.
62+
"""
63+
NULL,
64+
"""
65+
Throw the error.
66+
Parent fields can recover using `RESULT` or `NULL`.
67+
If no parent field recovers, the parsing stops.
68+
"""
69+
THROW
70+
}
71+
72+
"""
73+
Never throw on field errors.
74+
75+
This is used for backward compatibility for clients where this was the default behaviour.
76+
"""
77+
directive @ignoreErrors on QUERY | MUTATION | SUBSCRIPTION
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# nullability v0.1
2+
3+
<h2>Experimental nullability directives</h2>
4+
5+
```raw html
6+
<table class=spec-data>
7+
<tr><td>Status</td><td>Release</td>
8+
<tr><td>Version</td><td>0.1</td>
9+
</table>
10+
<link rel=stylesheet href=https://specs.apollo.dev/apollo-light.css>
11+
<script type=module async defer src=https://specs.apollo.dev/inject-logo.js></script>
12+
```
13+
14+
This specification provides a list of directives to help dealing with nullability. For more information, see [the nullability working group GitHub repository.](https://github.com/graphql/nullability-wg)
15+
16+
17+
#! @semanticNonNull
18+
19+
:::[definition](nullability-v0.1.graphql#@semanticNonNull)
20+
21+
#! @catch
22+
23+
:::[definition](nullability-v0.1.graphql#@catch)
24+
25+
#! @ignoreErrors
26+
27+
:::[definition](nullability-v0.1.graphql#@ignoreErrors)

0 commit comments

Comments
 (0)