-
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 list coercion examples #515
Conversation
`[[Int]]` | `[1, 2, 3]` | Error: Incorrect item value | ||
`[[Int]]` | `[[1], [2, 3]]` | `[[1], [2, 3]]` | ||
`[[Int]]` | `[1, 2, 3]` | `[[1], [2], [3]]` | ||
`[[Int]]` | `[1, null, 3]` | `[[1], null, [3]]` |
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.
Both above cases are correct as is since this coercion applied only if:
http://facebook.github.io/graphql/June2018/#sec-Type-System.List
If the value passed as an input to a list type is NOT A LIST
@@ -1489,8 +1489,9 @@ Expected Type | Provided Value | Coerced Value | |||
`[Int]` | `[1, "b", true]` | Error: Incorrect item value | |||
`[Int]` | `1` | `[1]` | |||
`[Int]` | `null` | `null` | |||
`[[Int]]` | `[[1], [2, 3]]` | `[[1], [2, 3]` | |||
`[[Int]]` | `[1, 2, 3]` | Error: Incorrect item value | |||
`[[Int]]` | `[[1], [2, 3]]` | `[[1], [2, 3]]` |
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.
Fix already proposed in:
https://github.com/facebook/graphql/pull/493/files
The reference implementation seems to be consistent with my interpretation: graphql/graphql-js#1528 I don't think it would make sense any other way. If we accept that |
@leebyron Can you please comment on whenever this limitation was intentional? @jjergus My assumption here: is that spec trying to be conservative and introduce complexity only if it provides significant benefits.
|
This comment has been minimized.
This comment has been minimized.
@jjergus I did a small research and this was intentional change, see here: 007a93e
After rereading spec text I figure out why
And coerce according to next rule:
So On the other hand I'm closing issue since examples are fully in sync with specification text. |
The reference implementation is consistent with my interpretation (see the test cases I added in graphql/graphql-js#1528). Do you think the reference implementation is wrong and should be changed? |
@jjergus Yes, I think so even though it's actually harder to implement coercion according to the current specification. I don't know @leebyron original intention but bellow is my best guess. If we start to coerce arrays it will create ambiguity since you can use two strategies:
And both strategies are logical and have their pros & cons. On the other hand, they produce exactly the same result on scalars, e.g. |
This is quite interesting issue. I got curious and also tested it in sangria. Turns out it behaves in the same way as reference implementation. This implies that it violates the spec example: After thinking about it for some time, I would agree with @jjergus original proposal for changing the example and allow coercion: Here is my interpretation: Gven following 2 rules for list type input coercion from the spec:
I assume:
When I coerce input value (step 1): For value So my conclusion: reference implementation behaviour is compliant with the spec, but example ( If we will conclude that Have I missed something? The interpretation is a bit tricky :) |
@IvanGoncharov I also wanted to point out that according to the current list input coercion rules (and my interpretation of these rules), the only valid coerced value in this example is |
@jjergus @OlegIlyenko Just to clarify both the rule But since we discussing it for so long it means that it wasn't written clearly enough.
This is a terminology problem since we don't have the clear definition.
@OlegIlyenko Thanks for suggesting better terminology, we should definitely use terms like
You are completely correct about what would be the correct behavior according to the spec assuming such coercion is allowed. What I meant is that if GraphQL user sees Note: As I said in my previous comment I assume this PR is about clarifying specification to better explain original intention and not an RFC for a proposed change. So I just wrote my best guess on why So I propose to keep this PR open until we get necessary clarifications from Lee. |
This may have been closed in error due to deletion of master branch, however I cannot reopen it on mobile. Cc @IvanGoncharov |
@IvanGoncharov @leebyron I've encountered the same issue, while covering list input coercion in |
Someone should add this topic to the next GraphQL Working Group, this seems to be an inconsistency between the spec and the reference implementation and should be solved one way or the other: https://github.com/graphql/graphql-wg/blob/main/agendas/2022/2022-01-06.md @ilslv Would you like to do so? |
I believe this example is inconsistent with this part of the spec:
Specifically the part about how "this may apply recursively for nested lists" is applicable here.