You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/blog/2024-08-14-semantic-nullability-for-application-developers.mdx
+18-14Lines changed: 18 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ byline: Alex Reilly
9
9
10
10
> This blog post is directed at application developers using GraphQL. If you are a library author, you should read the more detailed feature spec instead.
11
11
12
+
Today we're providing a progress update from the Nullablility Working Group on Semantic Nullability which is our new approach to fixing GraphQL's nullability issues.
13
+
12
14
GraphQL has some fundamental problems, and to talk about them, we first have to talk about GraphQL's type system. GraphQL allows you to define a schema, and to do that many developers write a document in Schema Definition Language, or SDL. A SDL document may look like this
13
15
14
16
```graphql
@@ -42,34 +44,36 @@ The root of the problem is that developers want a way to express that all `User`
Thiswillopenuptheoptiontobeginevolvingyourschema document by document. You can place the document directive `@extendedNullability` at the top of a file to begin using the new type of nullability in that file. The directive will not impact the interpretation of any other files in your schema.
58
+
Thiswillopenuptheoptiontobeginevolvingyourschema document by document. You can place the document directive `@SemanticNullability` at the top of a file to begin using the new nullability features in that file. The directive will not impact the interpretation of any other files in your schema.
56
59
57
60
After migration, a `User` type would look like this.
58
61
59
62
```graphql
60
63
@extendedNullability
61
64
62
65
type User {
63
-
id: ID!!
64
-
name: String!!
65
-
age: Int!
66
-
posts: [Post!]!
66
+
id: ID!
67
+
name: String!
68
+
age: Int
69
+
posts: [Post]
67
70
}
68
71
```
69
72
70
73
We can now trust that `age` and `posts` will never be null unless an error causes their values to fail to resolve.
74
+
71
75
### Frontend migration
72
-
Client libraries and code generation tools that support Semantic Nullability may provide a flags to alter their error handling behavior. In this example, `ApolloClient` is providing a configuration option that causes the access of a field with an error to throw.
76
+
Client libraries that take advantage of the new features in this release may provide a flags to alter their error handling behavior. In this example, `ApolloClient` is providing a configuration option that causes the access of a field with an error to throw.
73
77
74
78
```typescript
75
79
const client =newApolloClient({
@@ -82,7 +86,7 @@ Semantic Nullability gives clients and GraphQL tools more flexibility in how the
82
86
83
87
Because your client can decide how it handles errors, it will also be responsible for providing a modified version of the schema. For example, if the client raises an exception when an errored field is read, it can mark all "semantically non-null" fields as non-nullable in the schema provided to you as a frontend developer.
0 commit comments