-
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
Support non-list variables for list arguments #1043
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Example stepping through logic for
|
Note that no rules have changed for how default values for variables work. Since all existing nullability checks apply to the outermost layer, all are still valid with these new rules, in line with 'option 5' outlined in #1033. |
- If {itemLocationType} is a non-null type: | ||
- Let {nullableItemLocationType} be the unwrapped nullable type of {itemLocationType}. | ||
- Return {AreTypesCompatible(variableType, nullableItemLocationType)}. | ||
- Otherwise, return {AreTypesCompatible(variableType, itemLocationType)}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is simpler to write and equally as effective (and potentially more understandable):
- If {itemLocationType} is a non-null type: | |
- Let {nullableItemLocationType} be the unwrapped nullable type of {itemLocationType}. | |
- Return {AreTypesCompatible(variableType, nullableItemLocationType)}. | |
- Otherwise, return {AreTypesCompatible(variableType, itemLocationType)}. | |
- If {itemLocationType} is a non-null type: | |
- Let {nonNullVariableType} be the non-null type of {variableType}. | |
- Return AreTypesCompatible(nonNullVariableType, itemLocationType). |
However, all the rest of the logic favors unwrapping types, rather than wrapping types. So with a single extra line in the logic here, we are only unwrapping types, and never wrapping types.
GraphQL.NET's implementation of this is here, locked behind an experimental option flag: |
If you haven't already, please consider adding this to an upcoming GraphQL Working Group. Let me know if you need any guidance. https://github.com/graphql/graphql-wg/tree/main/agendas/2023 |
Oops, just saw #1033 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change alone is not sufficient; the behavior must also be adopted in CoerceArgumentValues
:
https://spec.graphql.org/draft/#sec-Coercing-Field-Arguments
Specifically 5.f.iii.
- Let value be the value provided in variableValues for the name variableName.
Would need to become something like:
- Let {variableValue} be the value provided in {variableValues} for the name {variableName}.
- If {hasValue} is {false}, or {variableValue} is {null}, or {variableValue} is a list, or {argumentType} is neither a list type nor a non-null list type, or {variableType} is either a list type or a non-null list type, then:
- Let {value} be {variableValue}.
- Otherwise:
- Let {value} be a list containing the single value {variableValue}.
Further we'd need to change logic in coercion too, for which it would be wise to land #1058 first.
I think we'd wrap all of that above in its own algorithm, something like:
|
Before working any more on this, I recommend that we land:
I then have edits in mind that I think would make this a clearer win. |
See this feature request: