Skip to content

Prioritize count error over null error in @oneOf coercion#1891

Merged
ruudk merged 2 commits intomasterfrom
improve-one-of-validation
Apr 2, 2026
Merged

Prioritize count error over null error in @oneOf coercion#1891
ruudk merged 2 commits intomasterfrom
improve-one-of-validation

Conversation

@ruudk
Copy link
Copy Markdown
Collaborator

@ruudk ruudk commented Apr 1, 2026

When a client sends multiple fields for a @OneOf input (e.g. one non-null and one null), the "must specify exactly one field" error is more actionable than "field X must be non-null", which misleadingly suggests providing a value for the null field.

This aligns Value::coerceInputValue with the existing behavior in OneOfInputObjectsRule, which already checks count before null.

@ruudk ruudk requested a review from spawnia April 1, 2026 13:28
Copy link
Copy Markdown
Collaborator

@spawnia spawnia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can you fix PHPStan?
  2. Does graphql-js also implement it this way and does it have tests that cover this?

When a client sends multiple fields for a @OneOf input (e.g. one
non-null and one null), the "must specify exactly one field" error
is more actionable than "field X must be non-null", which misleadingly
suggests providing a value for the null field.

This aligns Value::coerceInputValue with the existing behavior in
OneOfInputObjectsRule, which already checks count before null.
@ruudk ruudk force-pushed the improve-one-of-validation branch from 0fac11b to eb8b2b0 Compare April 1, 2026 18:24
@ruudk
Copy link
Copy Markdown
Collaborator Author

ruudk commented Apr 1, 2026

@spawnia
Copy link
Copy Markdown
Collaborator

spawnia commented Apr 1, 2026

Yeah, looks like it. We try to follow those tests closely and reference them in PhpDoc. Might do an audit or more elegant rework at some point (PHP 8 Attributes maybe?, permalinks instead of plain names?).

@ruudk
Copy link
Copy Markdown
Collaborator Author

ruudk commented Apr 2, 2026

@spawnia ready for review

@spawnia
Copy link
Copy Markdown
Collaborator

spawnia commented Apr 2, 2026

Looking good. Feel free to merge and release.

@ruudk
Copy link
Copy Markdown
Collaborator Author

ruudk commented Apr 2, 2026

Somehow I feel reluctant releasing on this project. I think it's because of the release workflow. Do you have plans to automate this so that it becomes easier? On my own projects I don't use a changelog (which makes things easier) and I let GitHub generate the release notes. So then it's Merge, wait for CI to go green, create a new release, choose version, generate release notes, done.

@spawnia
Copy link
Copy Markdown
Collaborator

spawnia commented Apr 2, 2026

I opened #1893, we can discuss the solution there or in an adjacent PR.

@ruudk ruudk merged commit 63288b2 into master Apr 2, 2026
22 checks passed
@ruudk ruudk deleted the improve-one-of-validation branch April 2, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants