Skip to content

Commit 6da555d

Browse files
benjieleebyron
authored andcommitted
Remove CoerceArgumentValues() hasValue
An alternative to #1056 which fully removes the `hasValue` variable in favor of hopefully more clear conditions
1 parent b1a23de commit 6da555d

File tree

1 file changed

+51
-46
lines changed

1 file changed

+51
-46
lines changed

spec/Section 6 -- Execution.md

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,30 @@ CoerceVariableValues(schema, operation, variableValues):
104104
- Let {variableName} be the name of {variableDefinition}.
105105
- Let {variableType} be the expected type of {variableDefinition}.
106106
- Assert: {IsInputType(variableType)} must be {true}.
107-
- Let {defaultValue} be the default value for {variableDefinition}.
108-
- Let {hasValue} be {true} if {variableValues} provides a value for the name
109-
{variableName}.
110-
- Let {value} be the value provided in {variableValues} for the name
111-
{variableName}.
112-
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
113-
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
114-
according to the input coercion rules of {variableType}.
115-
- Add an entry to {coercedValues} named {variableName} with the value
116-
{coercedDefaultValue}.
117-
- Otherwise if {variableType} is a Non-Nullable type, and either {hasValue} is
118-
not {true} or {value} is {null}, raise a _request error_.
119-
- Otherwise if {hasValue} is {true}:
107+
- If {variableValues} has an entry named {variableName}, let {value} be its
108+
value:
120109
- If {value} is {null}:
110+
- If {variableType} is a Non-Nullable type, raise a _request error_.
121111
- Add an entry to {coercedValues} named {variableName} with the value
122112
{null}.
123113
- Otherwise:
124-
- If {value} cannot be coerced according to the input coercion rules of
125-
{variableType}, raise a _request error_.
126114
- Let {coercedValue} be the result of coercing {value} according to the
127-
input coercion rules of {variableType}.
115+
input coercion rules of {variableType}, or raise a _request error_.
128116
- Add an entry to {coercedValues} named {variableName} with the value
129117
{coercedValue}.
118+
- Otherwise if {variableDefinition} has a default value, let it be
119+
{defaultValue}:
120+
- If {defaultValue} is {null}:
121+
- Assert: {variableType} is not a Non-Nullable type.
122+
- Add an entry to {coercedValues} named {variableName} with the value
123+
{null}.
124+
- Otherwise:
125+
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
126+
according to the input coercion rules of {variableType}, or raise a
127+
_request error_.
128+
- Add an entry to {coercedValues} named {variableName} with the value
129+
{coercedDefaultValue}.
130+
- Otherwise if {variableType} is a Non-Nullable type, raise a _request error_.
130131
- Return {coercedValues}.
131132

132133
Note: This algorithm is very similar to {CoerceArgumentValues()}.
@@ -742,46 +743,50 @@ At each argument position in an operation may be a literal {Value}, or a
742743
CoerceArgumentValues(objectType, field, variableValues):
743744

744745
- Let {coercedValues} be an empty unordered Map.
745-
- Let {argumentValues} be the argument values provided in {field}.
746+
- Let {arguments} be the {Arguments} provided in {field}.
746747
- Let {fieldName} be the name of {field}.
747748
- Let {argumentDefinitions} be the arguments defined by {objectType} for the
748749
field named {fieldName}.
749750
- For each {argumentDefinition} in {argumentDefinitions}:
750751
- Let {argumentName} be the name of {argumentDefinition}.
751752
- Let {argumentType} be the expected type of {argumentDefinition}.
752-
- Let {defaultValue} be the default value for {argumentDefinition}.
753-
- Let {hasValue} be {true} if {argumentValues} provides a value for the name
754-
{argumentName}.
755-
- Let {argumentValue} be the value provided in {argumentValues} for the name
756-
{argumentName}.
757-
- If {argumentValue} is a {Variable}:
758-
- Let {variableName} be the name of {argumentValue}.
759-
- Let {hasValue} be {true} if {variableValues} provides a value for the name
760-
{variableName}.
761-
- Let {value} be the value provided in {variableValues} for the name
762-
{variableName}.
763-
- Otherwise, let {value} be {argumentValue}.
764-
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
765-
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
766-
according to the input coercion rules of {argumentType}.
767-
- Add an entry to {coercedValues} named {argumentName} with the value
768-
{coercedDefaultValue}.
769-
- Otherwise if {argumentType} is a Non-Nullable type, and either {hasValue} is
770-
not {true} or {value} is {null}, raise an _execution error_.
771-
- Otherwise if {hasValue} is {true}:
772-
- If {value} is {null}:
753+
- Assert: {IsInputType(argumentType)} must be {true}.
754+
- If {arguments} has an {Argument} with name {argumentName}, let
755+
{argumentValue} be its {Value}:
756+
- If {argumentValue} is a {Variable}, let {variableName} be its name:
757+
- If {variableValues} has an entry named {variableName}, let
758+
{variableValue} be its value:
759+
- If {argumentType} is a Non-Nullable type and {variableValue} is
760+
{null}, raise an _execution error_ (see [note](#note-0aed8)).
761+
- Add an entry to {coercedValues} named {argumentName} with the value
762+
{variableValue}.
763+
- Otherwise if {argumentType} is a Non-Nullable type, raise an _execution
764+
error_.
765+
- Otherwise:
766+
- If {argumentValue} is {null} type:
767+
- If {argumentType} is a Non-Nullable type, raise an _execution error_.
768+
- Add an entry to {coercedValues} named {variableName} with the value
769+
{null}.
770+
- Otherwise:
771+
- Let {coercedValue} be the result of coercing {argumentValue} according
772+
to the input coercion rules of {argumentType}, or raise an _execution
773+
error_.
774+
- Add an entry to {coercedValues} named {argumentName} with the value
775+
{coercedValue}.
776+
- Otherwise if {argumentDefinition} has a default value, let it be
777+
{defaultValue}:
778+
- If {defaultValue} is {null}:
779+
- Assert: {argumentType} is not a Non-Nullable type.
773780
- Add an entry to {coercedValues} named {argumentName} with the value
774781
{null}.
775-
- Otherwise, if {argumentValue} is a {Variable}:
776-
- Add an entry to {coercedValues} named {argumentName} with the value
777-
{value}.
778782
- Otherwise:
779-
- If {value} cannot be coerced according to the input coercion rules of
780-
{argumentType}, raise an _execution error_.
781-
- Let {coercedValue} be the result of coercing {value} according to the
782-
input coercion rules of {argumentType}.
783+
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
784+
according to the input coercion rules of {argumentType}, or raise an
785+
_execution error_.
783786
- Add an entry to {coercedValues} named {argumentName} with the value
784-
{coercedValue}.
787+
{coercedDefaultValue}.
788+
- Otherwise if {argumentType} is a Non-Nullable type, raise an _execution
789+
error_.
785790
- Return {coercedValues}.
786791

787792
Any _request error_ raised as a result of input coercion during

0 commit comments

Comments
 (0)