graphql / graphql/graphql-spec
[Feature request]: Support non-list variables for list arguments
- Dominant language
- JavaScript
- Stars
- 14.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Currently this query which would fail validation due to the [All Variable Usages Are Allowed rule](https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed)'s explicit validation steps:
```gql
type Query {
dummy (arg: [String]): String
}
query ($arg: String) {
dummy(arg: $arg)
}
```
This is because of the text:
> Otherwise, if locationType is a list type:
> - If variableType is NOT a list type, return false.
However, the following queries are fine because of [list input coercion rules](https://spec.graphql.org/draft/#sec-List.Input-Coercion):
```gql
query {
dummy(arg: "test")
}
```
and
```gql
query ($arg: [String]) {
dummy(arg: $arg)
}
# variables: { "arg": "test" }
```
Because of the text:
> If the value passed as an input to a list type is not a list and not the null value, then the result of input coercion is a list of size one, where the single item value is the result of input coercion for the list’s item type on the provided value (note this may apply recursively for nested lists).
I propose modifying the [All Variable Usages Are Allowed rule](https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed) to allow for passing a scalar or input object to a list type (if the child type matches of course), and thereby allowing the query at the top of this feature request. I could write a PR if desired. It would be a fully backwards-compatible feature.
Contributor guide
Assessment
This issue has not been assessed yet.