Skip to content

Remove CoerceArgumentValues() hasValue #1178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 51 additions & 46 deletions spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,30 @@ CoerceVariableValues(schema, operation, variableValues):
- Let {variableName} be the name of {variableDefinition}.
- Let {variableType} be the expected type of {variableDefinition}.
- Assert: {IsInputType(variableType)} must be {true}.
- Let {defaultValue} be the default value for {variableDefinition}.
- Let {hasValue} be {true} if {variableValues} provides a value for the name
{variableName}.
- Let {value} be the value provided in {variableValues} for the name
{variableName}.
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
according to the input coercion rules of {variableType}.
- Add an entry to {coercedValues} named {variableName} with the value
{coercedDefaultValue}.
- Otherwise if {variableType} is a Non-Nullable type, and either {hasValue} is
not {true} or {value} is {null}, raise a _request error_.
- Otherwise if {hasValue} is {true}:
- If {variableValues} has an entry named {variableName}, let {value} be its
value:
- If {value} is {null}:
- If {variableType} is a Non-Nullable type, raise a _request error_.
- Add an entry to {coercedValues} named {variableName} with the value
{null}.
- Otherwise:
- If {value} cannot be coerced according to the input coercion rules of
{variableType}, raise a _request error_.
- Let {coercedValue} be the result of coercing {value} according to the
input coercion rules of {variableType}.
input coercion rules of {variableType}, or raise a _request error_.
- Add an entry to {coercedValues} named {variableName} with the value
{coercedValue}.
- Otherwise if {variableDefinition} has a default value, let it be
{defaultValue}:
- If {defaultValue} is {null}:
- Assert: {variableType} is not a Non-Nullable type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this language of Assert different from the

If {variableType} is a Non-Nullable type, raise a request error.
above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default values have gone through request validation, so an error would have been thrown at validation time. I believe we use Assert in other places where that should be true.

It's a good flag though that this should be more clear. It would be nice for all asserts to link back to the validation rules which allow them to be assertions instead of conditions

- Add an entry to {coercedValues} named {variableName} with the value
{null}.
- Otherwise:
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
according to the input coercion rules of {variableType}, or raise a
_request error_.
- Add an entry to {coercedValues} named {variableName} with the value
{coercedDefaultValue}.
- Otherwise if {variableType} is a Non-Nullable type, raise a _request error_.
- Return {coercedValues}.

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

- Let {coercedValues} be an empty unordered Map.
- Let {argumentValues} be the argument values provided in {field}.
- Let {arguments} be the {Arguments} provided in {field}.
- Let {fieldName} be the name of {field}.
- Let {argumentDefinitions} be the arguments defined by {objectType} for the
field named {fieldName}.
- For each {argumentDefinition} in {argumentDefinitions}:
- Let {argumentName} be the name of {argumentDefinition}.
- Let {argumentType} be the expected type of {argumentDefinition}.
- Let {defaultValue} be the default value for {argumentDefinition}.
- Let {hasValue} be {true} if {argumentValues} provides a value for the name
{argumentName}.
- Let {argumentValue} be the value provided in {argumentValues} for the name
{argumentName}.
- If {argumentValue} is a {Variable}:
- Let {variableName} be the name of {argumentValue}.
- Let {hasValue} be {true} if {variableValues} provides a value for the name
{variableName}.
- Let {value} be the value provided in {variableValues} for the name
{variableName}.
- Otherwise, let {value} be {argumentValue}.
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
according to the input coercion rules of {argumentType}.
- Add an entry to {coercedValues} named {argumentName} with the value
{coercedDefaultValue}.
- Otherwise if {argumentType} is a Non-Nullable type, and either {hasValue} is
not {true} or {value} is {null}, raise an _execution error_.
- Otherwise if {hasValue} is {true}:
- If {value} is {null}:
- Assert: {IsInputType(argumentType)} must be {true}.
- If {arguments} has an {Argument} with name {argumentName}, let
{argumentValue} be its {Value}:
- If {argumentValue} is a {Variable}, let {variableName} be its name:
- If {variableValues} has an entry named {variableName}, let
{variableValue} be its value:
- If {argumentType} is a Non-Nullable type and {variableValue} is
{null}, raise an _execution error_ (see [note](#note-0aed8)).
- Add an entry to {coercedValues} named {argumentName} with the value
{variableValue}.
- Otherwise if {argumentType} is a Non-Nullable type, raise an _execution
error_.
- Otherwise:
- If {argumentValue} is {null} type:
- If {argumentType} is a Non-Nullable type, raise an _execution error_.
- Add an entry to {coercedValues} named {variableName} with the value
{null}.
- Otherwise:
- Let {coercedValue} be the result of coercing {argumentValue} according
to the input coercion rules of {argumentType}, or raise an _execution
error_.
- Add an entry to {coercedValues} named {argumentName} with the value
{coercedValue}.
- Otherwise if {argumentDefinition} has a default value, let it be
{defaultValue}:
- If {defaultValue} is {null}:
- Assert: {argumentType} is not a Non-Nullable type.
- Add an entry to {coercedValues} named {argumentName} with the value
{null}.
- Otherwise, if {argumentValue} is a {Variable}:
- Add an entry to {coercedValues} named {argumentName} with the value
{value}.
- Otherwise:
- If {value} cannot be coerced according to the input coercion rules of
{argumentType}, raise an _execution error_.
- Let {coercedValue} be the result of coercing {value} according to the
input coercion rules of {argumentType}.
- Let {coercedDefaultValue} be the result of coercing {defaultValue}
according to the input coercion rules of {argumentType}, or raise an
_execution error_.
- Add an entry to {coercedValues} named {argumentName} with the value
{coercedValue}.
{coercedDefaultValue}.
- Otherwise if {argumentType} is a Non-Nullable type, raise an _execution
error_.
- Return {coercedValues}.

Any _request error_ raised as a result of input coercion during
Expand Down