Skip to content

feat(graphql): allow fields to reference the root query type - #4196

Merged
kamilmysliwiec merged 1 commit into
masterfrom
feat/root-query-type-reference
Oct 26, 2026
Merged

kamilmysliwiec merged 1 commit into
masterfrom
feat/root-query-type-reference

Conversation

@kamilmysliwiec

Copy link
Copy Markdown
Member

PR Checklist

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

  • Feature

What is the current behavior?

In code first, there is no way to reference the generated root Query type from an object type field, so the "mutation payload query" pattern (a payload exposing query: Query!, common with Relay, so clients can refetch anything after a mutation in one round trip) needs a transformSchema workaround. @Field(() => 'Query') fails with "Cannot determine a GraphQL output type".

Issue Number: #2738

What is the new behavior?

Object type fields can return the generated root Query type by name:

@ObjectType()
class AddTodoPayload {
  @Field(() => Todo) todo: Todo;
  @Field(() => 'Query') query: object;
}

// resolver
return { todo, query: {} };

Output types could already be referenced by name, but the root types were never registered. QueryTypeFactory now registers the generated Query type, and since object type fields are resolved lazily (after the root types are built), the reference works without ordering changes. Only Query is registered: nested mutation fields would not execute serially. TypeDefinitionsStorage.clear() now also resets the name-based lookup between schema builds.

Schema first already supports this (query: Query! in SDL).

Does this PR introduce a breaking change?

  • Yes
  • No

Closes #2738

@kamilmysliwiec
kamilmysliwiec merged commit 2ae8a13 into master Oct 26, 2026
1 check 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.

Export GraphQL Root Types

1 participant