Skip to content
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/optimize value coercion check for OneOf type #4181

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

Cito
Copy link
Member

@Cito Cito commented Sep 7, 2024

Where a JavaScript value is coerced to a GraphQL OneOf Input Type, a null value should only be reported when the "one of" condition is satisfied. The code block starting at line 158 here that accesses keys[0] should not be executed if keys is empty or contains more than one item.

The PR fixes this by adding an else statement. Alternatively, the "if/else" branches could be reversed, and the keys.length !== 1 check should become a keys.length === 1 check.

@Cito Cito requested a review from a team as a code owner September 7, 2024 17:57
Copy link

netlify bot commented Sep 7, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 093678b
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66dc941541f5c500084780df
😎 Deploy Preview https://deploy-preview-4181--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Sep 7, 2024

Hi @Cito, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR
Copy link
Contributor

yaacovCR commented Sep 9, 2024

@Cito -- do you think there is some value in reporting multiple errors, i.e. if there are multiple keys, and some of them are null, multiple things are wrong? The code at present, heads toward that direction, checks the number of values, and checks the identity of the first, so you would get more detailed errors if there were two keys, first being null, but not more details errors if there were two keys with the second null.

Or possibly I have the flow wrong!

@yaacovCR
Copy link
Contributor

@Cito from feedback from @benjie on #4195, it seems like the correct style is one error per incorrect value, with the suggestion there to just include a more generic error message to catch all cases, so that if the incorrect number of keys are present or any are null, just emit an error message like:

"Within OneOf Input Object type "TestOneOfInputObject", exactly one field must be specified, and the value for that field must be non-null."

So I think that's the suggestion I would make here. The idea of #4195 is to add the pre-coercion checks => your bug fix for not emitting more than one error could be landed separately, before that. What do you think?

@yaacovCR
Copy link
Contributor

We can always combine the error messages in a separate PR.

@yaacovCR yaacovCR added the PR: bug fix 🐞 requires increase of "patch" version number label Oct 15, 2024
@yaacovCR yaacovCR merged commit 0767861 into graphql:main Oct 15, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bug fix 🐞 requires increase of "patch" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants