Skip to content

[RFC] Allow singular variables in list locations #509

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,10 @@ AreTypesCompatible(variableType, locationType):
* Let {nullableVariableType} be the nullable type of {variableType}.
* Return {AreTypesCompatible(nullableVariableType, locationType)}.
* Otherwise, if {locationType} is a list type:
* If {variableType} is NOT a list type, return {false}.
* If {variableType} is NOT a list type:
* Let {itemLocationType} be the unwrapped item type of {locationType}.
* Let {nullableItemLocationType} be the unwrapped nullable type of {itemLocationType} if {itemLocationType} is non-null, or {itemLocationType} if {itemLocationType} is nullable.
* Return {AreTypesCompatible(variableType, nullableItemLocationType)}.
* Let {itemLocationType} be the unwrapped item type of {locationType}.
* Let {itemVariableType} be the unwrapped item type of {variableType}.
* Return {AreTypesCompatible(itemVariableType, itemLocationType)}.
Expand All @@ -1884,7 +1887,7 @@ query intCannotGoIntoBoolean($intArg: Int) {

${intArg} typed as {Int} cannot be used as a argument to {booleanArg}, typed as {Boolean}.

List cardinality must also be the same. For example, lists cannot be passed into singular
List cardinality must be compatible. For example, lists cannot be passed into singular
values.

```graphql counter-example
Expand All @@ -1895,6 +1898,17 @@ query booleanListCannotGoIntoBoolean($booleanListArg: [Boolean]) {
}
```

However, for consistency with type coercion, singular values can be passed into lists,
including nullable singular values for nullable lists of non-nullable values.

```graphql example
query booleanCanGoIntoBooleanList($booleanArg: Boolean!) {
arguments {
booleanListArgField(booleanListArg: $booleanArg)
}
}
```

Nullability must also be respected. In general a nullable variable cannot
be passed to a non-null argument.

Expand Down
56 changes: 3 additions & 53 deletions spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ request is determined by the result of executing this operation according to the
ExecuteRequest(schema, document, operationName, variableValues, initialValue):

* Let {operation} be the result of {GetOperation(document, operationName)}.
* Let {coercedVariableValues} be the result of {CoerceVariableValues(schema, operation, variableValues)}.
* If {operation} is a query operation:
* Return {ExecuteQuery(operation, schema, coercedVariableValues, initialValue)}.
* Return {ExecuteQuery(operation, schema, variableValues, initialValue)}.
* Otherwise if {operation} is a mutation operation:
* Return {ExecuteMutation(operation, schema, coercedVariableValues, initialValue)}.
* Return {ExecuteMutation(operation, schema, variableValues, initialValue)}.
* Otherwise if {operation} is a subscription operation:
* Return {Subscribe(operation, schema, coercedVariableValues, initialValue)}.
* Return {Subscribe(operation, schema, variableValues, initialValue)}.

GetOperation(document, operationName):

Expand Down Expand Up @@ -67,48 +66,6 @@ not later change, or a service may validate a request once and memoize the
result to avoid validating the same request again in the future.


### Coercing Variable Values

If the operation has defined any variables, then the values for
those variables need to be coerced using the input coercion rules
of variable's declared type. If a query error is encountered during
input coercion of variable values, then the operation fails without
execution.

CoerceVariableValues(schema, operation, variableValues):

* Let {coercedValues} be an empty unordered Map.
* Let {variableDefinitions} be the variables defined by {operation}.
* For each {variableDefinition} in {variableDefinitions}:
* 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}):
* Add an entry to {coercedValues} named {variableName} with the
value {defaultValue}.
* Otherwise if {variableType} is a Non-Nullable type, and either {hasValue}
is not {true} or {value} is {null}, throw a query error.
* Otherwise if {hasValue} is true:
* If {value} is {null}:
* 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}, throw a query error.
* Let {coercedValue} be the result of coercing {value} according to the
input coercion rules of {variableType}.
* Add an entry to {coercedValues} named {variableName} with the
value {coercedValue}.
* Return {coercedValues}.

Note: This algorithm is very similar to {CoerceArgumentValues()}.


## Executing Operations

The type system, as described in the "Type System" section of the spec, must
Expand Down Expand Up @@ -591,9 +548,6 @@ CoerceArgumentValues(objectType, field, variableValues):
* If {value} is {null}:
* 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 {variableType}, throw a field error.
Expand All @@ -603,10 +557,6 @@ CoerceArgumentValues(objectType, field, variableValues):
value {coercedValue}.
* Return {coercedValues}.

Note: Variable values are not coerced because they are expected to be coerced
before executing the operation in {CoerceVariableValues()}, and valid queries
must only allow usage of variables of appropriate types.


### Value Resolution

Expand Down