Skip to content

Decode every root field of a GraphQL operation - #3526

Merged
velo merged 1 commit into
masterfrom
fix/3525-multi-root-fields
Aug 19, 2026
Merged

velo merged 1 commit into
masterfrom
fix/3525-multi-root-fields

Conversation

@velo

@velo velo commented Aug 19, 2026

Copy link
Copy Markdown
Member

Fixes #3525

GraphqlDecoder unwrapped data and decoded only the first root field, so an operation selecting two root fields — legal GraphQL, one round trip — silently dropped everything after the first.

Decoder

When data carries more than one key, the whole data map is converted into the return type, so each root field binds to its matching component/property. A single root field keeps unwrapping exactly as before (including array-to-single unwrapping and Optional), so existing clients are unaffected.

Code generation

feign-graphql-apt generated the return record from the first root field's type. It now mirrors the operation's own selection set when several root fields are selected — one component per root field, each with its own inner record:

@GraphqlQuery("""
    query authorPage($authorId: ID!) {
      books(authorId: $authorId) { id title }
      reviews(authorId: $authorId) { id rating }
    }
    """)
AuthorPage authorPage(String authorId);
public record AuthorPage(Optional<List<Books>> books, Optional<List<Reviews>> reviews) {

  public record Books(String id, String title) {}

  public record Reviews(String id, Integer rating) {}

}

Single-root-field queries still generate the record for that field's type.

Tests

  • GraphqlDecoderTest: multiple root fields into a record, mixed shapes (object + list), null root field, Optional return, errors with multiple root fields
  • GraphqlClientTest: end-to-end multi-root query over MockWebServer
  • GraphqlSchemaProcessorTest: multi-root generation, list/scalar shapes, single-root regression

mvn test -pl graphql,graphql-apt -am is green. READMEs for both modules document the behaviour.

🤖 Generated with Claude Code

Signed-off-by: Marvin Froeder <velo.br@gmail.com>
@velo
velo merged commit 02b8549 into master Aug 19, 2026
4 checks passed
@velo
velo deleted the fix/3525-multi-root-fields branch August 19, 2026 11:37
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.

feign-graphql: operations with more than one root field cannot be decoded

1 participant