Skip to content

fix(graphql): preserve names for multiple operations in one document - #3546

Open
Aschenbath wants to merge 1 commit into
glideapps:masterfrom
Aschenbath:fix/graphql-multiple-operations
Open

Aschenbath wants to merge 1 commit into
glideapps:masterfrom
Aschenbath:fix/graphql-multiple-operations

Conversation

@Aschenbath

Copy link
Copy Markdown

Description

Use each GraphQL operation's name when one input document contains multiple operations. Apply the source name override only when there is one source with one operation.

Related Issue

Fixes #3532.

Motivation and Context

A document can contain several named queries that share a fragment. The parser already builds a response type for each operation, but the input layer registers every response under the source name when there is only one source file. The second registration fails.

Previous Behaviour / Output

For example, a document with ViewerQuery, UserQuery, and a shared UserFields fragment fails with Internal error: Trying to add top-level with existing name. This also affects a query and a mutation in the same document.

New Behaviour / Output

The document produces separate ViewerQuery and UserQuery response types and converters. A single named or anonymous operation still uses the requested source name. Multiple source files retain their existing operation naming behavior.

How Has This Been Tested?

  • Before the fix, four new regression cases failed with the reported duplicate-name error; three compatibility cases passed. All seven cases pass after the fix.
  • The regression reads a shared-fragment GraphQL fixture and JSON response fixtures, generates JavaScript, round-trips both responses, and rejects each response through the other operation's converter. These tests use the input API because the existing GraphQL language drivers assume one fixed top-level response name.
  • Windows, Node 24.22.0: npm run build, all 248 unit tests, and npm run lint passed.
  • Linux, Node 24.22.0: build, all seven new regression cases, and all 18 existing JavaScript/TypeScript GraphQL fixture cases passed (QUICKTEST=true FIXTURE=graphql-javascript,graphql-typescript CPUs=2 npm run test:fixtures).
  • CLI checks generated JavaScript, Swift, and Kotlin for the same document. The generated JavaScript round-tripped both responses and rejected crossed responses. Swift and Kotlin output was inspected; native compilation of those outputs was not run locally.

Screenshots (if appropriate):

Not applicable.

AI disclosure: implementation, tests, and this PR description were produced with OpenAI GPT-6 through Codex. The change was reviewed against the source and verified with the checks listed above.

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.

[QUESTION]/[BUG]: GraphQL input document with multiple queries (operations) fails with "Trying to add top-level with existing name"

1 participant