Skip to content

Commit 00aeec5

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 00aeec5

File tree

1 file changed

+22
-50
lines changed

1 file changed

+22
-50
lines changed

spec/Section 6 -- Execution.md

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,17 @@ 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}):
107+
- If {variableValues} has an entry named {variableName}, let {value} be its value:
108+
- Let {coercedValue} be the result of coercing {value} according to the
109+
input coercion rules of {variableType}, or raise a _request error_.
110+
- Add an entry to {coercedValues} named {variableName} with the value
111+
{coercedValue}.
112+
- Otherwise if {variableDefinition} has a default value, let it be {defaultValue}:
113113
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
114-
according to the input coercion rules of {variableType}.
114+
according to the input coercion rules of {variableType}, or raise a _request error_.
115115
- Add an entry to {coercedValues} named {variableName} with the value
116116
{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}:
120-
- If {value} is {null}:
121-
- Add an entry to {coercedValues} named {variableName} with the value
122-
{null}.
123-
- Otherwise:
124-
- If {value} cannot be coerced according to the input coercion rules of
125-
{variableType}, raise a _request error_.
126-
- Let {coercedValue} be the result of coercing {value} according to the
127-
input coercion rules of {variableType}.
128-
- Add an entry to {coercedValues} named {variableName} with the value
129-
{coercedValue}.
117+
- Otherwise if {variableType} is a Non-Nullable type, raise a _request error_.
130118
- Return {coercedValues}.
131119

132120
Note: This algorithm is very similar to {CoerceArgumentValues()}.
@@ -742,46 +730,30 @@ At each argument position in an operation may be a literal {Value}, or a
742730
CoerceArgumentValues(objectType, field, variableValues):
743731

744732
- Let {coercedValues} be an empty unordered Map.
745-
- Let {argumentValues} be the argument values provided in {field}.
733+
- Let {arguments} be the {Arguments} provided in {field}.
746734
- Let {fieldName} be the name of {field}.
747735
- Let {argumentDefinitions} be the arguments defined by {objectType} for the
748736
field named {fieldName}.
749737
- For each {argumentDefinition} in {argumentDefinitions}:
750738
- Let {argumentName} be the name of {argumentDefinition}.
751739
- 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}:
773-
- Add an entry to {coercedValues} named {argumentName} with the value
774-
{null}.
775-
- Otherwise, if {argumentValue} is a {Variable}:
776-
- Add an entry to {coercedValues} named {argumentName} with the value
777-
{value}.
740+
- Assert: {IsInputType(argumentType)} must be {true}.
741+
- If {arguments} has an {Argument} with name {argumentName}, let {argumentValue} be its {Value}:
742+
- If {argumentValue} is a {Variable}, let {variableName} be its name:
743+
- If {variableValues} has an entry named {variableName}, let {variableValue} be its value:
744+
- Add an entry to {coercedValues} named {argumentName} with the value {value}.
745+
- Otherwise if {argumentType} is a Non-Nullable type, raise a _execution error_.
778746
- Otherwise:
779-
- If {value} cannot be coerced according to the input coercion rules of
780-
{argumentType}, raise an _execution error_.
781747
- Let {coercedValue} be the result of coercing {value} according to the
782-
input coercion rules of {argumentType}.
748+
input coercion rules of {argumentType}, or raise a _execution error_.
783749
- Add an entry to {coercedValues} named {argumentName} with the value
784750
{coercedValue}.
751+
- Otherwise if {argumentDefinition} has a default value, let it be {defaultValue}:
752+
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
753+
according to the input coercion rules of {argumentType}, or raise a _execution error_.
754+
- Add an entry to {coercedValues} named {argumentName} with the value
755+
{coercedDefaultValue}.
756+
- Otherwise if {argumentType} is a Non-Nullable type, raise a _execution error_.
785757
- Return {coercedValues}.
786758

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

0 commit comments

Comments
 (0)