@@ -115,9 +115,6 @@ and floating-point values, they are interpreted as an integer input value if
115
115
they have an empty fractional part (ex. ` 1.0 ` ) and otherwise as floating-point
116
116
input value.
117
117
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
-
121
118
** Built-in Scalars**
122
119
123
120
GraphQL provides a basic set of well-defined Scalar types. A GraphQL server
@@ -812,21 +809,16 @@ input ExampleInputObject {
812
809
813
810
Original Value | Variables | Coerced Value
814
811
-------------------------------------------------------------------------------
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 }
820
815
`{ b : $var }` | `{ var : 123 }` | `{ b : 123 }`
821
- `{ b : $var }` | `{}` | Error : Missing required field {b }.
822
816
`{ 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 .
823
819
`{ a : $var , b : 1 }` | `{ var : null }` | `{ a : null , b : 1 }`
824
820
`{ a : $var , b : 1 }` | `{}` | `{ b : 1 }`
825
821
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
-
830
822
#### Input Object type validation
831
823
832
824
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
875
867
response for all of the above types . To declare a type that disallows null ,
876
868
the GraphQL Non -Null type can be used . This type wraps an underlying type ,
877
869
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
879
871
exclamation mark is used to denote a field that uses a Non -Null type like this :
880
872
`name : String !`.
881
873
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
-
893
874
**Result Coercion **
894
875
895
876
In all of the above result coercions , {null } was considered a valid value .
@@ -900,41 +881,43 @@ must be raised.
900
881
901
882
**Input Coercion **
902
883
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 .
907
886
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 .
910
889
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 :
912
896
913
897
```!graphql
914
898
{
915
- fieldWithNonNullArg
899
+ field ( arg : null )
916
900
}
917
901
```
918
902
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:
920
905
921
- ``` ! graphql
906
+ ``` graphql
922
907
{
923
- fieldWithNonNullArg(nonNullArg: null)
908
+ field
924
909
}
925
910
```
926
911
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:
928
914
929
915
``` graphql
930
916
query withNullableVariable ($var : String ) {
931
- fieldWithNonNullArg ( nonNullArg : $var )
917
+ field ( arg : $var )
932
918
}
933
919
```
934
920
935
- Note: The Validation section defines providing a nullable variable type to
936
- a non-null input type as invalid.
937
-
938
921
** Non-Null type validation**
939
922
940
923
1 . A Non-Null type must not wrap another Non-Null type.
0 commit comments