Skip to content

fix: report nullable OneOf variables in non-null positions - #5005

Open
eisen0419 wants to merge 1 commit into
graphql:17.x.xfrom
eisen0419:fix/oneof-nonnull-parent-variable-validation
Open

eisen0419 wants to merge 1 commit into
graphql:17.x.xfrom
eisen0419:fix/oneof-nonnull-parent-variable-validation

Conversation

@eisen0419

Copy link
Copy Markdown

Fixes #5004

Summary

In VariablesInAllowedPositionRule, parentType comes from TypeInfo.getParentInputType(), which retains the GraphQLNonNull wrapper when a OneOf Input Object sits in a non-null position (such as pet: PetInput!, an item of [PetInput!]! / [PetInput!], or a non-null input field OuterInput.pet: PetInput!). As a result, isInputObjectType(parentType) returned false and nullable variables used for OneOf fields in non-null positions were not reported as required by §5.8.5 (AllVariableUsagesAreAllowed) of the GraphQL specification.

Changes

  • Unwrap parentType via getNullableType(parentType) before checking isInputObjectType and isOneOf in VariablesInAllowedPositionRule, formatting the error message with the unwrapped OneOf Input Object type name ("PetInput").
  • Add regression tests in src/validation/__tests__/VariablesInAllowedPositionRule-test.ts covering non-null OneOf arguments, non-null list items ([PetInput!]! and [PetInput!]), nested non-null input object fields, nullable variables with default values, fragment variables, and valid non-null variables.

getParentInputType() keeps the Non-Null wrapper, so a nullable variable in a OneOf field was not reported for PetInput! or [PetInput!].
@vercel

vercel Bot commented Nov 15, 2026

Copy link
Copy Markdown

@eisen0419 is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: eisen0419 / name: eisen0419 (942b25e)

This branch has not been deployed

No deployments
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.

VariablesInAllowedPositionRule: nullable variable in a OneOf field isn't reported when the OneOf input is in a Non-Null position

1 participant