Skip to content

[visitor-plugin-common] feat: add documentMode plainString - #11011

Merged
eddeee888 merged 2 commits into
masterfrom
claude/quirky-darwin-elesza
Oct 12, 2026
Merged

eddeee888 merged 2 commits into
masterfrom
claude/quirky-darwin-elesza

Conversation

@eddeee888

@eddeee888 eddeee888 commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR adds documentMode: 'plainString', which makes _gql() return a bare template string with fragments embedded, so the generated output has no TypedDocumentString class, no import and no type cast.

#10873 asks for documentMode: string to produce plain strings with no runtime class. Existing string mode is unchanged, so this is opt-in and non-breaking.

With string:

export const PersonDocument = new TypedDocumentString(`
    query Person { person(id: 1) { ...PersonDetails } }
    fragment PersonDetails on Person { id name }`) as unknown as TypedDocumentString<PersonQuery, PersonQueryVariables>;

With plainString:

export const PersonDetailsFragmentDoc = `
    fragment PersonDetails on Person { id name }
    `;
export const PersonDocument = `
    query Person { person(id: 1) { ...PersonDetails } }
    fragment PersonDetails on Person { id name }`;

Related #10873

What changed

  • visitor-plugin-common (client-side-base-visitor.ts):
    • Adds DocumentMode.plainString.
    • Embeds fragments in this mode the same way string mode does.
    • _gql() returns the bare template string.
    • The documentMode docs now describe both string and plainString. string wasn't described there before.
  • typed-document-node: no source change. Its string branches don't match plainString, so the class template, the DocumentTypeDecoration import and the as unknown as ... cast are all skipped. Adds an inline-snapshot test.
  • A minor changeset for both packages.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • New typed-document-node inline-snapshot test: plainString output with an embedded fragment. It checks that no import, class or cast is generated.
  • Lint, format and type check pass.
  • Full vitest run: 88 failures in cli, graphql-modules-preset and examples-typescript-graphql-request. The same 88 fail on master without this change; the only difference is the new passing test.

Test Environment:

  • OS: Linux
  • @graphql-codegen/visitor-plugin-common, @graphql-codegen/typed-document-node: from this branch
  • NodeJS: 22.22.2

Further comments

Known gaps:

  • No operation types. In plainString mode, documents are typed as string, so they don't carry result or variables types. This is intentional: the mode exists to emit plain strings without a type cast.
  • No metadata. plainString documents carry no __meta__: no onExecutableDocumentNode output, no fragment fragmentName, and no @defer deferredFields.
  • Client preset. The client preset doesn't special-case plainString; it already passes any documentMode through unvalidated. This is left as-is until it becomes an issue.
  • Community plugins. typescript-react-query and typescript-rtk-query in graphql-code-generator-community force documentMode: string and type their fetchers as TypedDocumentString. The reporter's setup needs a matching change there to use this mode.

🤖 Generated with Claude Code

https://claude.ai/code/session_013F2QpCXY9jqU8vHpGPwbXu

@changeset-bot

changeset-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c6e04d7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/typed-document-node Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-codegen/fragment-matcher 7.1.1-alpha-20261012105020-c6e04d7a8566a8caca3735cf74cd45f366ef80a2 npm ↗︎ unpkg ↗︎
@graphql-codegen/visitor-plugin-common 7.3.0-alpha-20261012105020-c6e04d7a8566a8caca3735cf74cd45f366ef80a2 npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 7.2.0-alpha-20261012105020-c6e04d7a8566a8caca3735cf74cd45f366ef80a2 npm ↗︎ unpkg ↗︎

Generates documents as plain template strings with fragments embedded,
without the TypedDocumentString class, its import, or a type cast.

Refs #10873

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013F2QpCXY9jqU8vHpGPwbXu
@eddeee888
eddeee888 force-pushed the claude/quirky-darwin-elesza branch from b690e1a to 0857570 Compare September 30, 2026 10:39
@eddeee888 eddeee888 changed the title Add documentMode plainString [visitor-plugin-common] feat: add documentMode plainString Sep 30, 2026
@eddeee888
eddeee888 merged commit b3fbb13 into master Oct 12, 2026
12 checks passed
@eddeee888
eddeee888 deleted the claude/quirky-darwin-elesza branch October 12, 2026 10:49
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