Skip to content

Commit 13194df

Browse files
authored
Clarify execution section. (#221)
* Clarify execution section. This adds algorithms to the section on execution and reorders content to better follow the flow of execution. Note that no additional semantics are being introduced in this PR. This is simply algorithmic clarification of the execution process. * Follow up improvements thanks to @jjergus feedback * Another pass at further improvements to describing these operations. Included @jjergus's suggestion of getting rid of the tuple based response keying. * Note about the purpose of initial value * Add default value rules, further error throwing spots
1 parent ebf1921 commit 13194df

File tree

3 files changed

+468
-232
lines changed

3 files changed

+468
-232
lines changed

spec/Section 3 -- Type System.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,50 @@ An input object is never a valid result.
775775

776776
**Input Coercion**
777777

778-
The input to an input object should be an unordered map, otherwise an error
779-
should be thrown. The result of the coercion is an unordered map, with an
780-
entry for each input field, whose key is the name of the input field.
781-
The value of an entry in the coerced map is the result of input coercing the
782-
value of the entry in the input with the same key; if the input does not have a
783-
corresponding entry, the value is the result of coercing null. The input
784-
coercion above should be performed according to the input coercion rules of the
778+
The value for an input object should be an input object literal or an unordered
779+
map, otherwise an error should be thrown. This unordered map should not contain
780+
any entries with names not defined by a field of this input object type,
781+
otherwise an error should be thrown.
782+
783+
If any non-nullable fields defined by the input object do not have corresponding
784+
entries in the original value, were provided a variable for which a value was
785+
not provided, or for which the value {null} was provided, an error should
786+
be thrown.
787+
788+
The result of coercion is an environment-specific unordered map defining slots
789+
for each field both defined by the input object type and provided by the
790+
original value.
791+
792+
For each field of the input object type, if the original value has an entry with
793+
the same name, and the value at that entry is a literal value or a variable
794+
which was provided a runtime value, an entry is added to the result with the
795+
name of the field.
796+
797+
The value of that entry in the result is the outcome of input coercing the
798+
original entry value according to the input coercion rules of the
785799
type declared by the input field.
786800

801+
Following are examples of Input Object coercion for the type:
802+
803+
```graphql
804+
input ExampleInputObject {
805+
a: String
806+
b: Int!
807+
}
808+
```
809+
810+
Original Value | Variables | Coerced Value
811+
-------------------------------------------------------------------------------
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}
815+
`{ b: $var }` | `{ var: 123 }` | `{ b: 123 }`
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.
819+
`{ a: $var, b: 1 }` | `{ var: null }` | `{ a: null, b: 1 }`
820+
`{ a: $var, b: 1 }` | `{}` | `{ b: 1 }`
821+
787822
#### Input Object type validation
788823

789824
1. An Input Object type must define one or more fields.

0 commit comments

Comments
 (0)