Skip to content

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

Merged
tomhoule merged 1 commit into
graphql-rust:mainfrom
antonshevchenko:no-empty-enum-for-typename-only-selection
Aug 7, 2026
Merged

Keep a selection of only __typename as a struct, not an empty enum#573
tomhoule merged 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
Contributor

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

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

lgtm!

@tomhoule
tomhoule merged commit 840d632 into graphql-rust:main Aug 7, 2026
10 of 11 checks passed
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.

2 participants