Skip to content

Merge inline fragments whose type condition is the enclosing type - #572

Open
antonshevchenko wants to merge 1 commit into
graphql-rust:mainfrom
antonshevchenko:merge-same-type-inline-fragments
Open

Merge inline fragments whose type condition is the enclosing type#572
antonshevchenko wants to merge 1 commit into
graphql-rust:mainfrom
antonshevchenko:merge-same-type-inline-fragments

Conversation

@antonshevchenko

Copy link
Copy Markdown
Contributor

A type condition equal to the enclosing type is a no-op per the spec, but the codegen discards the fragment's selections.

When the fragment is the only selection, the result is an empty enum that can never deserialize:

query Example {
  thing {                 # returns the concrete object type `Thing`
    ... on Thing { name }
  }
}

generates pub enum ExampleThing {}, and every response fails with unknown variant `Thing`, there are no variants.

When the parent selects anything else, it compiles and the fields silently vanish:

query Example {
  thing {
    id
    ... on Thing { name }   # `name` is absent from the generated struct
  }
}

Fixes #394, #416.

A type condition equal to the enclosing type is a no-op per the spec, but
the codegen discarded the fragment's selections: when the fragment is the
only selection the result is an empty enum, and when the parent selects
anything else the fields silently vanish.

Co-authored-by: Cursor <cursoragent@cursor.com>
@antonshevchenko
antonshevchenko marked this pull request as ready for review August 5, 2026 00:33

@tomhoule tomhoule left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you for the contribution.

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.

unknown variant, there are no variants

2 participants