Add OneOf Inhabitability validation#4250
Closed
Copilot wants to merge 3 commits intovalidation-refactorfrom
Closed
Add OneOf Inhabitability validation#4250Copilot wants to merge 3 commits intovalidation-refactorfrom
Copilot wants to merge 3 commits intovalidation-refactorfrom
Conversation
Co-authored-by: andimarek <[email protected]>
Copilot
AI
changed the title
[WIP] Re-implement OneOf inhabitability validation for new architecture
Add OneOf Inhabitability validation
Feb 19, 2026
Member
|
@copilot The rule should be inlined |
Co-authored-by: andimarek <[email protected]>
Contributor
Author
Member
|
@copilot this PR should not start from master but from the PR we want to merge into |
Contributor
Author
The PR is configured to target the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements validation to detect uninhabited OneOf input types - types where no finite value can be constructed due to unresolvable cyclic references.
Based on GraphQL spec proposal #1211, adapted for the
validation-refactorbranch architecture.Problem
Self-referential or cyclical OneOf types without escape paths are uninhabited:
Changes
SchemaValidationErrorType: AddedOneOfNotInhabitederror classificationTypeAndFieldRule: Inlined all OneOf validation logic into this consolidated schema validation rule class:visitGraphQLInputObjectFieldmethod for field-level validation (nullable and no default value checks)visitGraphQLInputObjectTypemethod with recursive cycle detection viacanBeProvidedAFiniteValuetrueif any field references: scalar, enum, list, or non-OneOf input typefalseif all fields form unresolvable OneOf cyclesSchemaValidator: Removed separateOneOfInputObjectRulesfrom rules list (OneOf validation now part ofTypeAndFieldRule)Original prompt
Context
This PR re-implements the functionality from PR #4248 ("OneOf Inhabitability" by @jbellenger) but based on the
validation-refactorbranch (PR #4228), since #4228 will be merged first.PR #4248 targets
masterand adds validation for uninhabited OneOf input types. Since PR #4228 significantly refactors validation (consolidating 31 rule classes into a singleOperationValidator, removingAbstractRule,RulesVisitor, and individual rule classes), the OneOf inhabitability changes need to be adapted to work with the new validation architecture.What needs to be implemented
The core feature is validating that OneOf input types are "inhabited" — i.e., that a finite value can be constructed for them. A self-referential OneOf like
input A @oneOf { a: A }is uninhabited because you can never construct a finite value for it.This is based on the spec proposal at graphql/graphql-spec#1211
Changes needed (adapted from PR #4248 to the validation-refactor architecture):
1.
src/main/java/graphql/schema/validation/SchemaValidationErrorType.javaAdd a new enum value
OneOfNotInhabited(betweenOneOfNonNullableFieldandRequiredInputFieldCannotBeDeprecated).2.
src/main/java/graphql/schema/validation/OneOfInputObjectRules.javaAdd a new method
visitGraphQLInputObjectTypethat checks if a OneOf input object type is inhabited. If not, it adds aSchemaValidationErrorwith typeOneOfNotInhabited.Add the following logic (from PR #4248):
New imports needed:
3.
src/test/groovy/graphql/schema/validation/OneOfInputObjectRulesTest.groovyAdd the following 10 test cases after the existing tests:
"oneOf with scalar fields is inhabited"-input A @oneOf { a: String, b: Int }→ no exception"oneOf with enum field is inhabited"-input A @oneOf { a: Color }withenum Color { RED GREEN BLUE }→ no exception"oneOf with list field is inhabited"-input A @oneOf { a: [A] }→ no exception"oneOf referencing non-oneOf input is inhabited"-input A @oneOf { a: RegularInput }withinput RegularInput { x: String }→ no exception"oneOf with escape field is inhabited"-input A @oneOf { b: B, escape: String }withinput B @oneOf { a: A }→ no exception"mutually referencing oneOf types with scalar escape is inhabited"-input A @oneOf { b: B }withinput B @oneOf { a: A, escape: Int }→ no exception"oneOf referencing non-oneOf with back-reference is inhabited"-input A @oneOf { b: RegularInput }withinput RegularInput { back: A }→ no exception"multiple fields with chained oneOf escape is inhabited"-input A @oneOf { b: B, c: C },input B @oneOf { a: A },input C @oneOf { a: A, escape: String }→ no exception"single oneOf self-reference cycle is not inhabited"-input A @oneOf { self: A }→InvalidSchemaExceptionwith 1 error of typeOneOfNotInhabited"multiple oneOf types forming cycle are not inhabited"-input A @oneOf { b: B }, `input B @oneo...This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.