Skip to content

Emit named GraphQL operations for generated tools#891

Merged
RhysSullivan merged 2 commits into
RhysSullivan:mainfrom
oscnord:feat/named-graphql-operations
Jun 9, 2026
Merged

Emit named GraphQL operations for generated tools#891
RhysSullivan merged 2 commits into
RhysSullivan:mainfrom
oscnord:feat/named-graphql-operations

Conversation

@oscnord

@oscnord oscnord commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Problem

Generated GraphQL operations are anonymous — e.g. query($slug: ID!) { contentcollection(slug: $slug) { ... } }. Two consequences:

  • Servers that require named operations reject every invocation. (Apollo Server can be configured this way; some gateways enforce it unconditionally and return a 400 before the resolver runs.)
  • APM/observability tooling (Apollo Studio, New Relic, Datadog) keys traces and transaction names off the operation name, so all anonymous operations collapse into a single unnamed bucket.

Change

Derive an operation name from the root field and emit it in the generated document, so contentcollection produces:

query Contentcollection($slug: ID!) { contentcollection(slug: $slug) { ... } }
  • buildOperationStringForField and the anonymous fallback path both name the operation.
  • The name is the root field name with its first character upper-cased; GraphQL field names are already valid name tokens, so no further escaping is needed.
  • Each generated document contains exactly one operation, so there is no naming-collision concern.
  • The request body is unchanged otherwise; servers derive operationName from the document, so no separate operationName field is required.

Tests

Added a test asserting a query and a mutation are sent as named operations (query Hello …, mutation SetGreeting …). Full @executor-js/plugin-graphql suite passes; typecheck, oxfmt, and oxlint are clean.

@oscnord oscnord force-pushed the feat/named-graphql-operations branch from 6a0f85b to 3c7d2a3 Compare June 4, 2026 18:07
@RhysSullivan RhysSullivan force-pushed the feat/named-graphql-operations branch from 3c7d2a3 to 85e2b3e Compare June 9, 2026 05:32
@RhysSullivan

Copy link
Copy Markdown
Owner

Rebased this onto current main and fixed the stale test setup plus changeset target.\n\nValidation run locally on the rebased branch:\n- bun run --cwd packages/plugins/graphql test\n- bun run --cwd packages/plugins/graphql typecheck\n- bunx changeset status --since=origin/main\n- bun run format:check -- .changeset/named-graphql-operations.md packages/plugins/graphql/src/sdk/plugin.ts packages/plugins/graphql/src/sdk/plugin.test.ts

@RhysSullivan RhysSullivan merged commit 9c9bcb6 into RhysSullivan:main Jun 9, 2026
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