Skip to content
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

Add nullability directives #36

Merged
merged 13 commits into from
Dec 11, 2023
5 changes: 3 additions & 2 deletions __index__.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
- **[join/v0.1](/join/v0.1)** ([📄 graphql](join/v0.1/join-v0.1.graphql))
- **[join/v0.2](/join/v0.2)** ([📄 graphql](join/v0.2/join-v0.2.graphql))
- **[join/v0.3](/join/v0.3)** ([📄 graphql](join/v0.3/join-v0.3.graphql))
- **[kotlin_labs/v0.1](/kotlin_labs/v0.1)** ([📄 graphql](kotlin_labs/v0.1/kotlin_labs-v0.1.graphql))
- **[kotlin_labs/v0.2](/kotlin_labs/v0.2)** ([📄 graphql](kotlin_labs/v0.2/kotlin_labs-v0.2.graphql))
- **[link/v1.0](/link/v1.0)** ([📄 graphql](link/v1.0/link-v1.0.graphql))
- **[nullability/v0.1](/nullability/v0.1)** ([📄 graphql](nullability/v0.1/nullability-v0.1.graphql))
- **[tag/v0.1](/tag/v0.1)** ([📄 graphql](tag/v0.1/tag-v0.1.graphql))
- **[tag/v0.2](/tag/v0.2)** ([📄 graphql](tag/v0.2/tag-v0.2.graphql))
- **[kotlin_labs/v0.1](/kotlin_labs/v0.1)** ([📄 graphql](kotlin_labs/v0.1/kotlin_labs-v0.1.graphql))
- **[kotlin_labs/v0.2](/kotlin_labs/v0.2)** ([📄 graphql](kotlin_labs/v0.2/kotlin_labs-v0.2.graphql))
4 changes: 4 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

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

## nullability v0.1

[nullability v0.1](nullability/v0.1) incubating directives to work with nullability

# All Schemas

Everything in this library:
Expand Down
61 changes: 61 additions & 0 deletions nullability/v0.1/nullability-v0.1.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Indicates that a field is only null if there is a matching error in the `errors` array.
In all other cases, the field is non-null.

Tools doing code generation may use this information to generate the field as non-null.

This directive can be applied on field definitions:

```graphql
type User {
email: String @semanticNonNull
}
```

It can also be applied on object type extensions for use in client applications that do
not own the base schema:

```graphql
extend type User @semanticNonNull(field: "email")
```

Control over list items is done using the `level` argument:

```graphql
type User {
# friends is nullable but friends[0] is null only on errors
friends: [User] @semanticNonNull(level: 1)
}
```

@param field the name of the field if applied to an object definition or null if applied
to a field definition

@param level in case of a list type, level is the dimension where to apply the modifier,
starting at 0 if there is no list.
If level is null, the modifier is applied to all levels
"""
directive @semanticNonNull(field: String = null, level: Int = null) repeatable on FIELD_DEFINITION | OBJECT

"""
Indicates that a field acts as an error boundary in case of a GraphQL error.

By default, the first GraphQL error throws and fails the whole response.

@param level in case of a list type, level is the dimension where to apply the modifier,
starting at 0 if there is no list.
If level is null, the modifier is applied to all levels
"""
directive @catch(to: CatchTo! = RESULT, level: Int = null) repeatable on FIELD
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved

enum CatchTo {
NULL,
RESULT,
BoD marked this conversation as resolved.
Show resolved Hide resolved
}

"""
Never throw on errors.

This is used for backward compatibility for clients where this was the default behaviour.
"""
directive @ignoreErrors on QUERY | MUTATION | SUBSCRIPTION
BoD marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions nullability/v0.1/nullability-v0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# nullability v0.1

<h2>Experimental nullability directives</h2>

```raw html
<table class=spec-data>
<tr><td>Status</td><td>Release</td>
<tr><td>Version</td><td>0.1</td>
</table>
<link rel=stylesheet href=https://specs.apollo.dev/apollo-light.css>
<script type=module async defer src=https://specs.apollo.dev/inject-logo.js></script>
```

This specification provides a list of directives to help dealing with nullability. For more information, see [the nullability working group GitHub](https://github.com/graphql/nullability-wg)


#! @semanticNonNull

:::[definition](nullability-v0.1.graphql#@semanticNonNull)

#! @catch

:::[definition](nullability-v0.1.graphql#@catch)