-
Notifications
You must be signed in to change notification settings - Fork 2k
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
add additional runtime errors for pre-coercion OneOf errors #4195
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋 Supported commandsPlease post this commands in separate comments and only one per 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.
Thanks for your work on this! It seems right; but let's improve the error messages
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.
Just being picky over capitalisation now...
Do we generally capitalise Object Type
/ Interface Type
and so on in error messages? If so, the suggestions to reduce capitalization should be dismissed.
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 looks correct to me; great work!
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.
Should this be backported to v16
This PR ended up turning into a lot of editing of error messages, but contains the following two cases:
Assuming
Per non-normative graphql-js specific behavior, when the value for field is the JavaScript value I should probably extract both of these cases from this PR as two separate small PRs, and then they can be merged to v16.x.x. The diffuse changes to the error messages make this PR difficult to follow. |
Hmmm... Thanks for calling this out! We should only get one error for each mistake. I think when oneOf performs this "one field" check, it's actually checking that exactly one of its fields is set. From the spec edits:
There are some places in the spec where it suggests that it throws an error even if its not one of its fields:
This is just saying that an error must be thrown, not that this must throw an additional error. An existing error being thrown for an unknown field would be suitable in this case, as clarified through the coercion table:
This doesn't seem sufficiently clear though, so I'll edit the spec text so that oneof only applies these assertions to its own fields. |
Upon further reading, this clarification to the spec edits is not required. The spec already states:
This is the first thing to be stated before visiting any individual rules, thus I think the coercion rules can rely on this assumption. The coercion table also demonstrates this behavior. |
Thanks for exploring that one with me, I think you are right. I should also call out that there is an additional failure mode added by this PR that actually does not yet have a test case, namely, from the table at graphql/graphql-spec#825
If I'm not mistaken, the coerced value will just be |
This changes the implementation to match the specification.
Adds additional tests as well.