Skip to content

feat: @oneOf input directive support#2183

Open
samuelAndalon wants to merge 2 commits into
masterfrom
feat/add-one-of-directive-support
Open

feat: @oneOf input directive support#2183
samuelAndalon wants to merge 2 commits into
masterfrom
feat/add-one-of-directive-support

Conversation

@samuelAndalon

@samuelAndalon samuelAndalon commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📝 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.

  • Input validation/coercion — ValuesResolverOneOfValidation (source) enforces oneOf rules at execution time, per spec:

  • exactly one field supplied,

  • that field's value non-null,

  • rejects map with 0 or 2+ keys -> error before resolver runs.

    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

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant