Skip to content

Commit 8939e20

Browse files
committed
Default value coercion rules
1 parent 7a86a32 commit 8939e20

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

spec/Section 3 -- Type System.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ of rules must be adhered to by every Object type in a GraphQL schema.
818818
characters {"__"} (two underscores).
819819
2. The argument must accept a type where {IsInputType(argumentType)}
820820
returns {true}.
821+
3. If the argument has a default value, {defaultValue} must be compatible
822+
with {argumentType} as per the coercion rules for that type, and
823+
coercion of {defaultValue} must not cause an infinite loop.
821824
3. An object type may declare that it implements one or more unique interfaces.
822825
4. An object type must be a super-set of all interfaces it implements:
823826
1. Let this object type be {objectType}.
@@ -1520,10 +1523,11 @@ defined by the input object type and for which a value exists. The resulting map
15201523
is constructed with the following rules:
15211524

15221525
* If no value is provided for a defined input object field and that field
1523-
definition provides a default value, the default value should be used. If no
1524-
default value is provided and the input object field's type is non-null, an
1525-
error should be thrown. Otherwise, if the field is not required, then no entry
1526-
is added to the coerced unordered map.
1526+
definition provides a default value, the result of coercing the default value
1527+
according to the coercion rules of the input field type should be used.
1528+
If no default value is provided and the input object field's type is
1529+
non-null, an error should be thrown. Otherwise, if the field is not required,
1530+
then no entry is added to the coerced unordered map.
15271531

15281532
* If the value {null} was provided for an input object field, and the field's
15291533
type is not a non-null type, an entry in the coerced unordered map is given
@@ -1580,6 +1584,9 @@ Literal Value | Variables | Coerced Value
15801584
characters {"__"} (two underscores).
15811585
3. The input field must accept a type where {IsInputType(inputFieldType)}
15821586
returns {true}.
1587+
4. If the input field has a default value, {defaultValue} must be compatible
1588+
with {inputFieldType} as per the coercion rules for that type, and
1589+
coercion of {defaultValue} must not cause an infinite loop.
15831590
3. If an Input Object references itself either directly or through referenced
15841591
Input Objects, at least one of the fields in the chain of references must be
15851592
either a nullable or a List type.

spec/Section 6 -- Execution.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ CoerceVariableValues(schema, operation, variableValues):
8989
* Let {value} be the value provided in {variableValues} for the
9090
name {variableName}.
9191
* If {hasValue} is not {true} and {defaultValue} exists (including {null}):
92+
* Let {coercedDefaultValue} be the result of coercing {defaultValue} according to the
93+
input coercion rules of {variableType}.
9294
* Add an entry to {coercedValues} named {variableName} with the
93-
value {defaultValue}.
95+
value {coercedDefaultValue}.
9496
* Otherwise if {variableType} is a Non-Nullable type, and either {hasValue}
9597
is not {true} or {value} is {null}, throw a query error.
9698
* Otherwise if {hasValue} is true:
@@ -586,8 +588,10 @@ CoerceArgumentValues(objectType, field, variableValues):
586588
name {variableName}.
587589
* Otherwise, let {value} be {argumentValue}.
588590
* If {hasValue} is not {true} and {defaultValue} exists (including {null}):
591+
* Let {coercedDefaultValue} be the result of coercing {defaultValue} according to the
592+
input coercion rules of {argumentType}.
589593
* Add an entry to {coercedValues} named {argumentName} with the
590-
value {defaultValue}.
594+
value {coercedDefaultValue}.
591595
* Otherwise if {argumentType} is a Non-Nullable type, and either {hasValue}
592596
is not {true} or {value} is {null}, throw a field error.
593597
* Otherwise if {hasValue} is true:

0 commit comments

Comments
 (0)