@@ -805,29 +805,28 @@ An input object is never a valid result.
805805** Input Coercion**
806806
807807The value for an input object should be an input object literal or an unordered
808- map, otherwise an error should be thrown. This unordered map should not contain
809- any entries with names not defined by a field of this input object type,
810- otherwise an error should be thrown.
808+ map supplied by a variable, otherwise an error should be thrown. In either
809+ case, the input object literal or unordered map should not contain any entries
810+ with names not defined by a field of this input object type, otherwise an error
811+ should be thrown.
811812
812- If any non-nullable fields defined by the input object do not have corresponding
813- entries in the original value, were provided a variable for which a value was
814- not provided, or for which the value {null} was provided, an error should
815- be thrown.
813+ The result of coercion is an unordered map with an entry for each field both
814+ defined by the input object type and provided with a value. If the value {null}
815+ was provided, an entry in the coerced unordered map must exist for that field.
816+ In other words, there is a semantic difference between the explicitly provided
817+ value {null} versus having not provided a value.
816818
817- The result of coercion is an environment-specific unordered map defining slots
818- for each field both defined by the input object type and provided by the
819- original value.
819+ The value of each entry in the coerced unordered map is the result of input
820+ coercion of the value provided for that field for the type of the field defined
821+ by the input object type
820822
821- For each field of the input object type, if the original value has an entry with
822- the same name, and the value at that entry is a literal value or a variable
823- which was provided a runtime value, an entry is added to the result with the
824- name of the field .
823+ Any non-nullable field defined by the input object type which does not have
824+ a corresponding entry in the original value, or is represented by a variable
825+ which was not provided a value, or for which the value {null} was provided, an
826+ error should be thrown .
825827
826- The value of that entry in the result is the outcome of input coercing the
827- original entry value according to the input coercion rules of the
828- type declared by the input field.
829-
830- Following are examples of Input Object coercion for the type:
828+ Following are examples of input coercion for an input object type with a
829+ ` String ` field ` a ` and a required (non-null) ` Int! ` field ` b ` :
831830
832831``` graphql example
833832input ExampleInputObject {
@@ -836,22 +835,24 @@ input ExampleInputObject {
836835}
837836```
838837
839- Original Value | Variables | Coerced Value
840- ----------------------- | --------------- | -----------------------------------
841- `{ a : "abc" , b : 123 }` | {null } | `{ a : "abc" , b : 123 }`
842- `{ a : 123, b : "123" }` | {null } | `{ a : "123" , b : 123 }`
843- `{ a : "abc" }` | {null } | Error : Missing required field {b }
844- `{ a : "abc" , b : null }` | {null } | Error : {b } must be non -null .
845- `{ a : null , b : 1 }` | {null } | `{ a : null , b : 1 }`
846- `{ b : $var }` | `{ var : 123 }` | `{ b : 123 }`
847- `{ b : $var }` | `{}` | Error : Missing required field {b }.
848- `{ b : $var }` | `{ var : null }` | Error : {b } must be non -null .
849- `{ a : $var , b : 1 }` | `{ var : null }` | `{ a : null , b : 1 }`
850- `{ a : $var , b : 1 }` | `{}` | `{ b : 1 }`
851-
852- Note : there is a semantic difference between the input value
853- explicitly declaring an input field 's value as the value {null } vs having not
854- declared the input field at all .
838+ Literal Value | Variables | Coerced Value
839+ ------------------------ | ----------------------- | ---------------------------
840+ `{ a : "abc" , b : 123 }` | `{}` | `{ a : "abc" , b : 123 }`
841+ `{ a : null , b : 123 }` | `{}` | `{ a : null , b : 123 }`
842+ `{ b : 123 }` | `{}` | `{ b : 123 }`
843+ `{ a : $var , b : 123 }` | `{ var : null }` | `{ a : null , b : 123 }`
844+ `{ a : $var , b : 123 }` | `{}` | `{ b : 123 }`
845+ `{ b : $var }` | `{ var : 123 }` | `{ b : 123 }`
846+ `$var ` | `{ var : { b : 123 } }` | `{ b : 123 }`
847+ `"abc123" ` | `{}` | Error : Incorrect value
848+ `$var ` | `{ var : "abc123" } }` | Error : Incorrect value
849+ `{ a : "abc" , b : "123" }` | `{}` | Error : Incorrect value for field {b }
850+ `{ a : "abc" }` | `{}` | Error : Missing required field {b }
851+ `{ b : $var }` | `{}` | Error : Missing required field {b }.
852+ `$var ` | `{ var : { a : "abc" } }` | Error : Missing required field {b }
853+ `{ a : "abc" , b : null }` | `{}` | Error : {b } must be non -null .
854+ `{ b : $var }` | `{ var : null }` | Error : {b } must be non -null .
855+ `{ b : 123, c : "xyz" }` | `{}` | Error : Unexpected field {c }
855856
856857#### Input Object type validation
857858
0 commit comments