feat(10.x.x): @oneOf input directive support - #2193
Merged
Merged
Conversation
### 📝 Description Add support for GraphQL `@oneOf` directive for input objects . See: https://graphql.org/blog/2025-09-04-multioption-inputs-with-oneof/ https://spec.graphql.org/September2025/#sec-OneOf-Input-Objects #### What graphql-java provides graphql-java owns the directive definition and all input validation— runs before our convertArgumentValue: - Directive def — @OneOf SDL definition baked into [graphql-java](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/Directives.java#L244). - Input validation/coercion — ValuesResolverOneOfValidation (source) enforces oneOf rules at execution time, per spec: - exactly one field supplied, - [that field's value non-null](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/OneOfNullValueException.java), - [rejects map with 0 or 2+ keys -> error before resolver runs](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/OneOfTooManyKeysException.java). So by the time graphql-kotlin runtime code sees the argument map, it is already validated: guaranteed single non-null entry. That's why mapToOneOfKotlinObject can safely do input.entries.single() — no defensive count check needed. #### What graphql-java does NOT cover graphql-java works in graphql land. It knows nothing about Kotlin sealed types. It does not: - generate the @OneOf input object from Kotlin types - know which sealed subtype a given field maps to - construct the Kotlin instance at runtime during operation execution #### What graphql-kotlin adds 1. Schema generation (generateOneOfInputObject / generateOneOfInputProperty) - Kotlin sealed interface -> @OneOf input object. - Each subtype (@GraphQLOneOfField) -> one input field 2. Argument mapping (mapToOneOfKotlinObject in convertArgumentValue) - Takes the already-validated single-entry map from graphql-java. - Matches fieldName -> sealed subtype via @GraphQLOneOfField. ### 🔗 Related Issues #1891 ### Examples <img width="929" height="613" alt="image" src="https://github.com/user-attachments/assets/9517a631-cad5-4cbe-9ef6-e25daee7965e" /> <img width="937" height="569" alt="image" src="https://github.com/user-attachments/assets/3e7feb91-1409-441d-88f2-fb8fef8cdae2" /> --------- Co-authored-by: Samuel Vazquez <samvazquez@expediagroup.com>
Samjin
approved these changes
Jun 26, 2026
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.
📝 Description
cherry pick #2183