Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit b11793a

Browse files
committed
Revert "[RFC] Null value (graphql#83)"
This reverts commit 3ce8b79.
1 parent 3ce8b79 commit b11793a

File tree

5 files changed

+34
-94
lines changed

5 files changed

+34
-94
lines changed

spec/Appendix B -- Grammar Summary.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,12 @@ Value[Const] :
127127
- FloatValue
128128
- StringValue
129129
- BooleanValue
130-
- NullValue
131130
- EnumValue
132131
- ListValue[?Const]
133132
- ObjectValue[?Const]
134133

135134
BooleanValue : one of `true` `false`
136135

137-
NullValue : `null`
138-
139136
EnumValue : Name but not `true`, `false` or `null`
140137

141138
ListValue[Const] :

spec/Section 2 -- Language.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ Value[Const] :
634634
- FloatValue
635635
- StringValue
636636
- BooleanValue
637-
- NullValue
638637
- EnumValue
639638
- ListValue[?Const]
640639
- ObjectValue[?Const]
@@ -737,37 +736,6 @@ StringCharacter :: \ EscapedCharacter
737736
* Return the character value of {EscapedCharacter}.
738737

739738

740-
### Null Value
741-
742-
NullValue : `null`
743-
744-
Null values are represented as the keyword {null}.
745-
746-
GraphQL has two semantically different ways to represent the lack of a value:
747-
748-
* Explicitly providing the literal value: {null}.
749-
* Implicitly not providing a value at all.
750-
751-
For example, these two field calls are similar, but are not identical:
752-
753-
```graphql
754-
{
755-
field(arg: null)
756-
field
757-
}
758-
```
759-
760-
The first has explictly provided {null} to the argument "arg", while the second
761-
has implicitly not provided a value to the argument "arg". These two forms may
762-
be interpreted differently. For example, a mutation representing deleting a
763-
field vs not altering a field, respectively. Niether form may be used for an
764-
input expecting a Non-Null type.
765-
766-
Note: The same two methods of representing the lack of a value are possible via
767-
variables by either providing the a variable value as {null} and not providing
768-
a variable value at all.
769-
770-
771739
### Enum Value
772740

773741
EnumValue : Name but not `true`, `false` or `null`
@@ -777,6 +745,9 @@ recommended that Enum values be "all caps". Enum values are only used in
777745
contexts where the precise enumeration type is known. Therefore it's not
778746
necessary to supply an enumeration type name in the literal.
779747

748+
An enum value cannot be "null" in order to avoid confusion. GraphQL
749+
does not supply a value literal to represent the concept {null}.
750+
780751

781752
### List Value
782753

spec/Section 3 -- Type System.md

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ and floating-point values, they are interpreted as an integer input value if
115115
they have an empty fractional part (ex. `1.0`) and otherwise as floating-point
116116
input value.
117117

118-
For all types below, with the exception of Non-Null, if the explicit value
119-
{null} is provided, then then the result of input coercion is {null}.
120-
121118
**Built-in Scalars**
122119

123120
GraphQL provides a basic set of well-defined Scalar types. A GraphQL server
@@ -812,21 +809,16 @@ input ExampleInputObject {
812809

813810
Original Value | Variables | Coerced Value
814811
-------------------------------------------------------------------------------
815-
`{ a: "abc", b: 123 }` | | `{ a: "abc", b: 123 }`
816-
`{ a: 123, b: "123" }` | | `{ a: "123", b: 123 }`
817-
`{ a: "abc" }` | | Error: Missing required field {b}
818-
`{ a: "abc", b: null }` | | Error: {b} must be non-null.
819-
`{ a: null, b: 1 }` | | `{ a: null, b: 1 }`
812+
`{ a: "abc", b: 123 }` | `{}` | `{ a: "abc", b: 123 }`
813+
`{ a: 123, b: "123" }` | `{}` | `{ a: "123", b: 123 }`
814+
`{ a: "abc" }` | `{}` | Error: Missing required field {b}
820815
`{ b: $var }` | `{ var: 123 }` | `{ b: 123 }`
821-
`{ b: $var }` | `{}` | Error: Missing required field {b}.
822816
`{ b: $var }` | `{ var: null }` | Error: {b} must be non-null.
817+
`{ b: $var }` | `{}` | Error: {b} must be non-null.
818+
`{ b: $var }` | `{}` | Error: {b} must be non-null.
823819
`{ a: $var, b: 1 }` | `{ var: null }` | `{ a: null, b: 1 }`
824820
`{ a: $var, b: 1 }` | `{}` | `{ b: 1 }`
825821

826-
Note: there is a semantic difference between the input value
827-
explicitly declaring an input field's value as the value {null} vs having not
828-
declared the input field at all.
829-
830822
#### Input Object type validation
831823

832824
1. An Input Object type must define one or more fields.
@@ -875,21 +867,10 @@ By default, all types in GraphQL are nullable; the {null} value is a valid
875867
response for all of the above types. To declare a type that disallows null,
876868
the GraphQL Non-Null type can be used. This type wraps an underlying type,
877869
and this type acts identically to that wrapped type, with the exception
878-
that {null} is not a valid response for the wrapping type. A trailing
870+
that `null` is not a valid response for the wrapping type. A trailing
879871
exclamation mark is used to denote a field that uses a Non-Null type like this:
880872
`name: String!`.
881873

882-
**Nullable vs. Optional**
883-
884-
Fields are *always* optional within the context of a query, a field may be
885-
omitted and the query is still valid. However fields that return Non-Null types
886-
will never return the value {null} if queried.
887-
888-
Inputs (such as field arguments), are always optional by default. However a
889-
non-null input type is required. In addition to not accepting the value {null},
890-
it also does not accept omission. For the sake of simplicity nullable types
891-
are always optional and non-null types are always required.
892-
893874
**Result Coercion**
894875

895876
In all of the above result coercions, {null} was considered a valid value.
@@ -900,41 +881,43 @@ must be raised.
900881

901882
**Input Coercion**
902883

903-
If an argument or input-object field of a Non-Null type is not provided, is
904-
provided with the literal value {null}, or is provided with a variable that was
905-
either not provided a value at runtime, or was provided the value {null}, then
906-
a query error must be raised.
884+
If the argument of a Non-Null type is not provided, a query error must
885+
be raised.
907886

908-
If the value provided to the Non-Null type is provided with a literal value
909-
other than {null}, or a Non-Null variable value, it is coerced using the input coercion for the wrapped type.
887+
If an argument of a Non-Null type is provided with a literal value, it is
888+
coerced using the input coercion for the wrapped type.
910889

911-
Example: A non-null argument cannot be omitted.
890+
If the argument of a Non-Null is provided with a variable, a query error must be
891+
raised if the runtime provided value is not provided or is {null} in the
892+
provided representation (usually JSON). Otherwise, the coerced value is the
893+
result of using the input coercion for the wrapped type.
894+
895+
Note that `null` is not a value in GraphQL, so a query cannot look like:
912896

913897
```!graphql
914898
{
915-
fieldWithNonNullArg
899+
field(arg: null)
916900
}
917901
```
918902

919-
Example: The value {null} cannot be provided to a non-null argument.
903+
to indicate that the argument is {null}. Instead, an argument would be {null}
904+
only if it is omitted:
920905

921-
```!graphql
906+
```graphql
922907
{
923-
fieldWithNonNullArg(nonNullArg: null)
908+
field
924909
}
925910
```
926911

927-
Example: A variable of a nullable type cannot be provided to a non-null argument.
912+
Or if passed a variable of a nullable type that at runtime was not provided
913+
a value:
928914

929915
```graphql
930916
query withNullableVariable($var: String) {
931-
fieldWithNonNullArg(nonNullArg: $var)
917+
field(arg: $var)
932918
}
933919
```
934920

935-
Note: The Validation section defines providing a nullable variable type to
936-
a non-null input type as invalid.
937-
938921
**Non-Null type validation**
939922

940923
1. A Non-Null type must not wrap another Non-Null type.

spec/Section 5 -- Validation.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -629,26 +629,22 @@ fragment stringIntoInt on Arguments {
629629
```
630630

631631

632-
#### Required Non-Null Arguments
632+
#### Required Arguments
633633

634634
* For each Field or Directive in the document.
635635
* Let {arguments} be the arguments provided by the Field or Directive.
636636
* Let {argumentDefinitions} be the set of argument definitions of that Field or Directive.
637-
* For each {definition} in {argumentDefinitions}:
638-
* Let {type} be the expected type of {definition}.
639-
* If {type} is Non-Null:
640-
* Let {argumentName} be the name of {definition}.
637+
* For each {definition} in {argumentDefinitions}
638+
* Let {type} be the expected type of {definition}
639+
* If {type} is Non-Null
640+
* Let {argumentName} be the name of {definition}
641641
* Let {argument} be the argument in {arguments} named {argumentName}
642642
* {argument} must exist.
643-
* Let {value} be the value of {argument}.
644-
* {value} must not be the {null} literal.
645643

646644
** Explanatory Text **
647645

648646
Arguments can be required. Arguments are required if the type of the argument
649-
is non-null. If it is not non-null, the argument is optional. When an argument
650-
type is non-null, and is required, the explicit value {null} may also not
651-
be provided.
647+
is non-null. If it is not non-null, the argument is optional.
652648

653649
For example the following are valid:
654650

@@ -680,13 +676,6 @@ fragment missingRequiredArg on Arguments {
680676
}
681677
```
682678

683-
Providing the explicit value {null} is also not valid.
684-
685-
```!graphql
686-
fragment missingRequiredArg on Arguments {
687-
notNullBooleanArgField(nonNullBooleanArg: null)
688-
}
689-
```
690679

691680
## Fragments
692681

spec/Section 6 -- Execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ the field returned {null}, and an error must be added to the {"errors"} list
535535
in the response.
536536

537537
If the result of resolving a field is {null} (either because the function to
538-
resolve the field returned {null} or because an error occurred), and that
538+
resolve the field returned `null` or because an error occurred), and that
539539
field is of a `Non-Null` type, then a field error is thrown. The
540540
error must be added to the {"errors"} list in the response.
541541

0 commit comments

Comments
 (0)