Skip to content

Keep a selection of only __typename as a struct, not an empty enum - #573

Open
antonshevchenko wants to merge 1 commit into
graphql-rust:mainfrom
antonshevchenko:no-empty-enum-for-typename-only-selection
Open

Keep a selection of only __typename as a struct, not an empty enum#573
antonshevchenko wants to merge 1 commit into
graphql-rust:mainfrom
antonshevchenko:no-empty-enum-for-typename-only-selection

Conversation

@antonshevchenko

@antonshevchenko antonshevchenko commented Aug 5, 2026

Copy link
Copy Markdown

A union member selected with only __typename generates an enum with no variants. Nothing can deserialize into it.

mutation Example {
  doThing {
    __typename
    ... on DoThingSuccess { __typename }
  }
}

DoThingSuccess carries no fields, so __typename is the only thing there is to select. The generated payload type comes out as pub enum ExampleDoThingOnDoThingSuccess {}, and any response naming that member fails to decode.

The cause is in ExpandedSelection::render, where a selection with no fields is turned into the enum of its variants. A selection of only __typename has no fields and no variants, so it becomes an empty enum. Requiring at least one variant leaves it as a struct, which deserializes from any object.

`ExpandedSelection::render` turns a fieldless struct into the enum of its
variants. With no variants either -- a union member narrowed to with nothing
but `__typename` -- that produced `enum X {}`, which cannot deserialize.

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

1 participant