-
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
Fix coercion table for list #1057
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I think this is actually an editorial change since the text already states recursive, it's just a bug in the examples. cc @graphql/tsc |
relevant: This was discussed this at a WG meeting (i do not see notes for that meeting) As far as I recall: The consensus from the meeting was that the table was actually controlling in practice in that other implementations (Hot Chocolate?) had followed that explicit lead rather than the somewhat more ambiguous spec text. The thinking was that the single item to list coercion feature was apparently intended to only work when passed on a non-list -- even though it works to coerce to lists of lists in that case -- but never when initially passed a list of wrong order. So in some sense it works recursively, single item => list => list of lists, as the spec text clearly indicates, but only when you start from a non-list value, as the paragraph begins and the table makes clear. So the resolution of those present was that the safest option forward would be to make an editorial change to the spec text to make it more explicitly match the table (and a bug-fix to graphql-js to remove this behavior? maybe in a major revision) and and then, if desired, re-introduce any additional automatic coercion as a new spec and graphql-js feature. Importantly, I do not believe @leebyron nor you @benjie were present at the meeting. I think the action item we took away was to check back with @leebyron to see if there was any non-spec-preserved knowledge / recollection around the issue -- that may not have ever happened! |
Thanks for the extra detail @yaacovCR; in which case I'll move this back to being an RFC. Regarding the previous discussion you highlight: the GraphQL spec states (emphasis mine):
And the text leading into this table is (emphasis mine):
So I believe the correct interpretation is to follow the wording of the spec and to fix the mistake in the example table. Further, the spec text makes a lot more sense from the point of view of how coercion happens in general because it doesn't need to know the context of where it's running (am I inside of a list that's already being coerced?) - just the data and the thing you're coercing it to. |
Tagging @abhinand-c explicitly. |
I support this PR. Although the spec is confusing at first glance (specifying that list types are not coerced), this is a rule simply to force coercion 'down a level', so it is ** not ** ambiguous whether Besides fixing the sample, I might suggest adding an additional note to explain this rule and behavior, as it is confusing. GraphQL.NET coerces lists pursuant to the specification and as demonstrated within this PR, ignoring the sample. I'd be curious what the behavior of graphql.js is. I'd also like to point out that implementations that do not follow the spec can make this change as a non-breaking change to existing clients. However, changing the specification to disallow these types of coercions would be a breaking change for other implementations. |
I totally agree with the desire to clarify this further, and have written up a detailed algorithm which also covers the ambiguity of dealing with variables: |
@benjie For a first time GraphQL developer these coercion for nested list might seem a bit confusion. So, could you also mention the coercion example for |
b2ff6b3
to
7e13d5c
Compare
@abhinand-c Since this is just a bugfix I'll leave that out of this PR, but I'll add it to #1058 - thanks for the feedback! |
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.
👍 I agree the table needs to be fixed
- Given the reference impl (graphql-js) has had this behaviour all along, the impl is a better reflection of how GraphQL is used
- Changing the impls to match the table (returning an error) would be a breaking change. This change is moving to be more permissive of inputs and thus non-breaking.
Ship it!
This is seen by the attendees of tonight's WG as an editorial fix. (Further clarifications are in a separate PR #1058) I'm going to leave this open a couple of weeks, and then merge it unless there's any good reasons not to 👍 |
The spec claims:
[Int]
[1, 2, 3]
[1, 2, 3]
[Int]
1
[1]
[[Int]]
[1, 2, 3]
but this isn't correct. This final line should actually be:
[[Int]]
[1, 2, 3]
[[1], [2], [3]]
This is the behavior GraphQL.js has already.
Reproduction:
And it follows from the spec text:
I've fixed this, and added another couple of examples.
I will be following up with a separate PR that fixes another issue in list type coercion; but this should be an easy merge.