Skip to content

Fix __typename at the query root - #964

Open
hugo-vrijswijk wants to merge 1 commit into
mainfrom
typename-root
Open

hugo-vrijswijk wants to merge 1 commit into
mainfrom
typename-root

Conversation

@hugo-vrijswijk

Copy link
Copy Markdown
Contributor

Queries with __typename at the root failed with No field '__typename' for type Query. The compiler used the introspection schema's Query type to resolve it. That type has no __typename field.

This change resolves __typename against the enclosing type instead.

Queries with `__typename` at the root failed with `No field '__typename' for type Query`. The compiler used the introspection schema's `Query` type to resolve it. That type has no `__typename` field.

This change resolves `__typename` against the enclosing type instead.
@hugo-vrijswijk hugo-vrijswijk changed the title Fix __typename at the query root Fix __typename at the query root Oct 17, 2026

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

This is really useful ... thanks!

Just the issues I've flagged in the comments.

}

nonIntroResults.map(_ ++ introResults)
nonIntroResults.map(typenameResults ++ _ ++ introResults)

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.

In think this is going to mean that __typename always appears first in the result. eg. suppose we had { foo __typename } instead of { __typename foo }. I think there maybe similar pre-existing issues for non-top-level uses, but I'm pretty sure this is introducing a new instance.

val expected = json"""
{
"data" : {
"__typename" : "Query",

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.

It looks like the directive has been silently ignored here ... I'm pretty sure on main it would have been an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On main this would fail (in nested fields) with Undefined directive 'upperCase'.. The directive not changing __typename or other introspection fields was an intentional change here.
The GraphQL spec says "it (typename) returns the name of the concrete Object type at that point during execution". So I don't think any user elaborators should be able to change introspection-level fields.

@milessabin milessabin Oct 19, 2026 •

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.

Right, but I think we should still fail here in the same way as on main.

)
}

class TypenameShapesMapping extends ValueMapping[IO] {

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.

Is this actually used?

This branch has not been deployed

No deployments
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