Skip to content

fix: keep the query keyword after a bodyless definition - #4913

Open
nimbly1 wants to merge 1 commit into
graphql:17.x.xfrom
nimbly1:codex/print-query-after-bodyless-def
Open

nimbly1 wants to merge 1 commit into
graphql:17.x.xfrom
nimbly1:codex/print-query-after-bodyless-def

Conversation

@nimbly1

@nimbly1 nimbly1 commented Oct 23, 2026

Copy link
Copy Markdown

Fixes #4901.

print drops query from an anonymous query that has no name, variables, or directives, leaving the short form { ... }. When the previous definition omitted a brace body, the parser reads that { as the previous definition's body. Printing and parsing again either swallows the operation or produces a syntax error.

This happens after an object, interface, input, or enum definition or extension with no fields or values, and after a schema definition or extension with no operation types. The printer now keeps the query keyword in that case. A query that is first, or that follows a definition which already printed its body, still uses the short form.

Verification:

  • npm run node:test -- src/**/__tests__/**/*-test.ts passed 3112 tests. With coverage limited to src/language/printer.ts, lines, branches, and functions were all 100%.
  • npx eslint --max-warnings 0 and npx prettier --check passed on the two changed files.
  • npx tsc --noEmit passed.
  • npx cspell passed on the two changed files.

npm test was not run as one command. That script also runs the Deno publish dry-run and the integration tests.

print() dropped `query` from an anonymous query. After a type, interface,
input, enum, or schema definition that omitted its brace body, parsing the
printed document treated that selection set as the previous definition's body.
@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@nimbly1 is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: nimbly1 / name: nimbly1 (105f5ba)

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.

print() can change a document's meaning: shorthand query after a definition without a body

1 participant