Skip to content

Commit cd807eb

Browse files
authored
Simplify syntax comparison (#1670)
1 parent df8ea23 commit cd807eb

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

rfcs/SemanticNullability.md

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,17 @@ The community has imagined a variety of possible solutions, synthesized here.
512512
Each solution is identified with a `Number` so they can be referenced in the
513513
rest of the document. New solutions must be added to the end of the list.
514514

515+
Semantic nullability is only relevant to output positions, so when comparing
516+
syntax we will look for changes versus the current syntax used to represent
517+
these types:
518+
519+
| | Input syntax | Output syntax |
520+
| ------------------------- | ------------ | ------------- |
521+
| Semantically nullable | `Int` | `Int` |
522+
| Semantically non-nullable | - | `Int` |
523+
| Strictly non-nullable | `Int!` | `Int!` |
524+
525+
515526
## 💡 1. New "Semantic Non-Null" type, represented by `*`
516527

517528
[solution-1]: #-1-new-semantic-non-null-type-represented-by-
@@ -545,11 +556,11 @@ type Post {
545556

546557
Querying a semantic non-null field is the same as querying any other field.
547558

548-
| | Existing syntax | Proposed syntax |
549-
| ------------------------- | --------------- | --------------- |
550-
| Semantically nullable | `Int` | `Int` |
551-
| Semantically non-nullable | - | `Int*` |
552-
| Strictly non-nullable | `Int!` | `Int!` |
559+
| | Input syntax | Output syntax |
560+
| ------------------------- | --------------- | ------------------- |
561+
| Semantically nullable | `Int` | `Int` |
562+
| Semantically non-nullable | - | `Int` ⇒ `Int*` |
563+
| Strictly non-nullable | `Int!` | `Int!` |
553564

554565
### 🎲 Variations
555566

@@ -606,11 +617,11 @@ in schemas using this directive would now be semantically non-nullable by
606617
default, and a new semantically nullable type is introduced (using the `?`
607618
symbol) to indicate that a position may semantically be null.
608619

609-
| | Existing syntax | Proposed syntax |
610-
| ------------------------- | --------------- | --------------- |
611-
| Semantically nullable | `Int` | `Int?` |
612-
| Semantically non-nullable | - | `Int` |
613-
| Strictly non-nullable | `Int!` | `Int!` |
620+
| | Input syntax | Output syntax |
621+
| ------------------------- | -------------------- | ------------------- |
622+
| Semantically nullable | `Int` ⇒ ??? | `Int` ⇒ `Int?` |
623+
| Semantically non-nullable | - | `Int` |
624+
| Strictly non-nullable | `Int!` ⇒ ??? | `Int!` |
614625

615626
### ⚖️ Evaluation
616627

@@ -661,23 +672,26 @@ symbol) to indicate that a position may semantically be null.
661672

662673
This proposal is similar to proposal 1, but:
663674

664-
1. It introduces a document-level directive, `@semanticNullability`, which when
665-
present on a document allows the `!` suffix to be used to represent
666-
semantically non-nullable types, and a new `!!` suffix to be used to
667-
represent strictly non-nullable types:
675+
It introduces a document-level directive, `@semanticNullability`, which when
676+
present on a document allows the `!` suffix to be used to represent
677+
semantically non-nullable output types, and a new `!!` suffix to be used to
678+
represent strictly non-nullable output types.
679+
680+
The `Int!` syntax simply means "non-nullable" on input, as it always has.
681+
(Note: input types are always either semantically nullable or strictly
682+
non-nullable.)
668683

669-
| | Syntax without directive | Syntax with directive |
670-
| ------------------------- | ------------------------ | --------------------- |
671-
| Semantically nullable | `Int` | `Int` |
672-
| Semantically non-nullable | - | `Int!` |
673-
| Strictly non-nullable | `Int!` | `Int!!` |
684+
Syntax only changes when `@semanticNullability` directive is present:
674685

675-
As such all documents (both SDL and executable documents) retain their current
676-
meaning, and the semantically non-null type can be adopted on a per-document
677-
basis.
686+
| | Input syntax | Output syntax |
687+
| ------------------------- | ------------ | --------------------- |
688+
| Semantically nullable | `Int` | `Int` |
689+
| Semantically non-nullable | - | `Int` ⇒ `Int!` |
690+
| Strictly non-nullable | `Int!` | `Int!` ⇒ `Int!!` |
678691

679-
2. It allows using semantically non-nullable types in input positions, allowing
680-
the `Int!` syntax to simply mean "non-nullable" on input.
692+
All documents (both SDL and executable documents) retain their current meaning,
693+
and the semantically non-null type can be adopted in output positions on a
694+
per-document basis by adding the document directive.
681695

682696
Since there's no difference between whether a type is "semantically" or
683697
"strictly" non-nullable on input (input does not represent errors), executable
@@ -752,11 +766,14 @@ This proposal builds on solution 3, but with a syntactic shuffle such that the
752766
unadorned type may be used as the semantically non-nullable type when the
753767
directive is present, and a `?` symbol is used to indicate a nullable position.
754768

755-
| | Syntax without directive | Syntax with directive |
756-
| ------------------------- | ------------------------ | --------------------- |
757-
| Semantically nullable | `Int` | `Int?` |
758-
| Semantically non-nullable | - | `Int` |
759-
| Strictly non-nullable | `Int!` | `Int!` |
769+
Syntax only changes when `@semanticNullability` directive is present:
770+
771+
| | Input syntax | Output syntax |
772+
| ------------------------- | ------------------- | ------------------- |
773+
| Semantically nullable | `Int` ⇒ `Int?` | `Int` ⇒ `Int?` |
774+
| Semantically non-nullable | - | `Int` |
775+
| Strictly non-nullable | `Int!` ⇒ `Int` | `Int!` |
776+
760777

761778
### ⚖️ Evaluation
762779

@@ -810,6 +827,12 @@ directive is present, and a `?` symbol is used to indicate a nullable position.
810827

811828
This proposal relies on the ability of clients to opt out of error propagation; instead of introducing a new type it instructs schema authors to optimize for error-handling clients and use the traditional non-null type (`!`) on all semantically non-null fields.
812829

830+
| | Input syntax | Output syntax |
831+
| ------------------------- | ------------ | ------------------- |
832+
| Semantically nullable | `Int` | `Int` |
833+
| Semantically non-nullable | - | `Int` ⇒ `Int!` |
834+
| Strictly non-nullable | `Int!` | `Int!` |
835+
813836
### ⚖️ Evaluation
814837

815838
- [A][criteria-a]

0 commit comments

Comments
 (0)