-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Feature request]: Support non-list variables for list arguments #1033
Comments
I agree with the need for this; it would make changing a field from a non-list type to a list type a non-breaking change. Currently it's only non-breaking when using explicit values, but with variables it is a breaking change due to validation. Your proposal to write a PR would be the best way to start - raise the PR with the necessary changes (ideally both against GraphQL-js and against GraphQL-spec, but one or the other is sufficient), and then add it to an upcoming agenda: https://github.com/graphql/graphql-wg/tree/main/agendas/2023 . If you're unable to represent this via WG attendance, let me know and I may be able to represent it on your behalf. |
I hadn't thought of that, but that's potentially an even more important reason than adding the feature. As I was thinking about how to write the PR here, I realized that the handling of
We also within GraphQL make a distinction between undefined and an explicit
Note that depending on which option we select, we may limit the amount of scenarios in which changing a type to a list type is backwards compatible. For instance, with option 5, changing We also see here that if options 2/3/4 were selected, coercion would be illogical if no variable were provided, since there is no default argument value for a non-null argument. So as such, my suggestion is option 5. This means that to make |
IMO as much as possible you should be able to replace a value |
Option 5 most definitely has the least impact on the GraphQL specification. This is likely a good indicator that it presents the least changes existing codebases. |
A pull request for graphql-spec has been added here: A corresponding pull request for GraphQL.NET has been merged here (support is locked behind an experimental option flag until the spec is finalized): @benjie Feel free to represent this feature at a future WG meeting. (If I can join, I will, but don't wait for me..) |
Added to November WG: graphql/graphql-wg#1416 |
Summary from November 2023 WG: Two viewpoints:
Actual scenario where this was encountered involved changing a sort-by enum field to a list field to allow for a secondary sort. @benjie and @Shane32 have encountered this issue in production schemas. While not a breaking change if the sort-by was specified as a literal, it breaks requests where it was specified by a variable. Action items:
|
Relevant spec text stating why non-list to list coercion exists: https://spec.graphql.org/draft/#sel-GAHjBJHABAB8H86F |
My opinion: you should always be able to replace a literal with a variable that has the same value, and the meaning of the request should not change. Different coercion for variables vs literals w.r.t. list values breaks this. I'm not aware of anything else that breaks this specifically input coercion concern? |
Currently this query which would fail validation due to the All Variable Usages Are Allowed rule's explicit validation steps:
This is because of the text:
However, the following queries are fine because of list input coercion rules:
and
Because of the text:
I propose modifying the All Variable Usages Are Allowed rule 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.
The text was updated successfully, but these errors were encountered: