Skip to content

Commit 64c7f2e

Browse files
RFC: Trim down CCN proposal (#1358)
1 parent 6a329e0 commit 64c7f2e

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

rfcs/ClientControlledNullability.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ nullability of fields for individual operations.
1717

1818
- **Required field** - A field which is marked with `!`.
1919

20-
- **Optional field** - A field which is marked with `?`.
21-
2220
## 📜 Problem Statement
2321

2422
In our experience, client developers have been frustrated that the vast majority of fields are
@@ -45,24 +43,16 @@ logic.
4543

4644
## 🧑‍💻 Proposed Solution
4745

48-
Client-controlled Non-Nullable and Nullable designators.
46+
A client-controlled Non-Nullable designator.
4947

5048
## 🎬 Behavior
5149

52-
Each client controlled nullability designator overrides the schema-defined nullability of the field
50+
Each client-controlled nullability designator overrides the schema-defined nullability of the field
5351
it's attached to for the duration of the operation.
5452

5553
### `!`
56-
The proposed client-controlled required designator would have similar, but not identical semantics to the current
57-
schema-defined [Non-Null](https://spec.graphql.org/draft/#sec-Executing-Selection-Sets.Errors-and-Non-Null-Fields).
58-
Specifically if a required field resolves to `null`, then `null` propagation extends to the nearest optional
59-
parent rather than the nearest nullable parent. In the event that no optional parent exists, the `data` field
60-
of the response will be `null`.
61-
62-
### `?`
63-
The proposed client-controlled optional designator would have identical semantics to the current
64-
schema-defined default behavior. Fields that resolve to `null` return `null` for that field. Additionally,
65-
fields marked with `?` act as a stopping point for `null` propagation caused by required fields.
54+
The proposed client-controlled required designator would have identical semantics to the current
55+
schema-defined [Non-Null](https://spec.graphql.org/draft/#sec-Executing-Selection-Sets.Errors-and-Non-Null-Fields).
6656

6757
## ✅ Validation
6858

@@ -99,11 +89,6 @@ query GetBusinessName($id: String!) {
9989
We have chosen `!` because `!` is already being used in the GraphQL spec to indicate that a field in
10090
the schema is Non-Nullable, so it will feel familiar to GraphQL developers.
10191

102-
### `?`
103-
104-
We have chosen `?` because `?` is used in a few other languages (Swift, Kotlin) that have `!` to
105-
mean something like the opposite of `!`.
106-
10792
## Use cases
10893

10994
### Improve the developer experience using GraphQL client code generators
@@ -147,7 +132,6 @@ utilize.
147132
## ✅ RFC Goals
148133

149134
- Non-nullable syntax that is based off of syntax that developers will already be familiar with
150-
- Nullable syntax that is based off of syntax that developers will already be familiar with
151135
- Enable GraphQL client code generation tools to generate more ergonomic types
152136

153137
## 🚫 RFC Non-goals
@@ -280,6 +264,23 @@ precedent.
280264

281265
## Decision Log
282266

267+
### `!` as the only designator in the RFC (July 2023)
268+
269+
At the July 26th meeting of the CCN sub-WG it was decided to simplify the RFC for the sake of progress. This
270+
reverses the "`?` as a counterpart to the `!`" designator.
271+
272+
The increased scope of the RFC with the nullability designator `?` has stalled the RFC for more than two
273+
years ([the initial RFC from April 2021](https://github.com/twof/graphql-spec/pull/1/files)).
274+
275+
One of the contentious discussions we encountered was around the proposed behaviors of the nullability designator
276+
`?`. Regardless of the chosen path, it had unintuitive semantics (see graphql/client-controlled-nullability-wg#2),
277+
which require other RFCs, such as [fragment boundaries](https://github.com/graphql/graphql-wg/blob/main/rfcs/FragmentModularity.md), or new ideas like inline errors.
278+
279+
Even though we recognize the value of having a counterpart to `!`, we made a tradeoff decision to provide value
280+
to the community sooner than later.
281+
282+
### Prior to July 2023
283+
283284
This proposal started out with a very simple premise and implementation, and has gotten more complex as
284285
the community has explored edge cases and facets about how GraphQL is actually used in practice. For
285286
example this proposal starts out by talking about accommodating the "best practices" that are recommended
@@ -293,7 +294,7 @@ log was written with newcomers in mind to avoid rediscussing issues that have al
293294
and to make it easier to understand why certain decisions have been made. At the time of writing,
294295
the decisions here aren't set in stone, so any future discussions can use this log as a starting point.
295296

296-
### `?` as a counterpart to `!`
297+
#### `?` as a counterpart to `!`
297298

298299
Lee was the first person [to suggest](https://github.com/graphql/graphql-spec/issues/867#issuecomment-840807186)
299300
that the inverse of `!` should exist and that it should be represented by `?`. The
@@ -317,7 +318,8 @@ Subsequently there was discussion around whether `?` could be introduced in a la
317318
agreement that the usability of `!` is limited without `?`, and the selected `null` propagation behavior described
318319
below solidifies the decision to introduce both additions in a single proposal.
319320

320-
### List syntax
321+
#### List syntax
322+
321323
Developers from Apollo [suggested](https://github.com/graphql/graphql-spec/pull/895#issuecomment-961442966) early
322324
on that users would want to apply CCN syntax to list elements. The possibility had been suggested earlier than
323325
that as well, but it was put off because neither Netflix nor Relay's CCN counterparts had the feature, and it
@@ -361,7 +363,8 @@ twoDimensionalList[[]]!
361363
There are however some open concerns that the first of the two examples could be ambiguous as to whether
362364
the `!` applies to the field as a whole or to the list elements.
363365

364-
### `!` propagates `null` to nearest `?` rather than nearest nullable field
366+
#### `!` propagates `null` to nearest `?` rather than nearest nullable field
367+
365368
The selected mechanics were most requested by the folks at Meta working on [Relay](https://relay.dev/).
366369
Relay wanted this behavior for a few reasons
367370
- Relay presents a facade of fragment isolation for its own

0 commit comments

Comments
 (0)