From 8707247857ecd77aaed6930b9eb6985323350932 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Tue, 2 Jun 2026 00:24:09 +1000 Subject: [PATCH 1/3] Add typedDocumentStringTemplate to re-use across client plugins (#10863) * Add typedDocumentStringTemplate to re-use across client plugins that need it * Add changeset --- .changeset/nice-goats-beg.md | 6 +++++ .changeset/tricky-brooms-ring.md | 6 +++++ .../other/visitor-plugin-common/src/index.ts | 1 + .../src/typed-document-string.ts | 24 +++++++++++++++++++ .../typed-document-node/src/index.ts | 23 ++---------------- 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 .changeset/nice-goats-beg.md create mode 100644 .changeset/tricky-brooms-ring.md create mode 100644 packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts diff --git a/.changeset/nice-goats-beg.md b/.changeset/nice-goats-beg.md new file mode 100644 index 00000000000..3f36aa8054c --- /dev/null +++ b/.changeset/nice-goats-beg.md @@ -0,0 +1,6 @@ +--- +'@graphql-codegen/typed-document-node': patch +--- + +Use typedDocumentStringTemplate from @graphql-codegen/visitor-plugin-common instead of the inline +version diff --git a/.changeset/tricky-brooms-ring.md b/.changeset/tricky-brooms-ring.md new file mode 100644 index 00000000000..0f5b0f028a7 --- /dev/null +++ b/.changeset/tricky-brooms-ring.md @@ -0,0 +1,6 @@ +--- +'@graphql-codegen/visitor-plugin-common': minor +--- + +Create typedDocumentStringTemplate to support TypedDocumentString usage (common in Client-side +plugins when documentMode=string) diff --git a/packages/plugins/other/visitor-plugin-common/src/index.ts b/packages/plugins/other/visitor-plugin-common/src/index.ts index b0a07031317..a82f6d865c0 100644 --- a/packages/plugins/other/visitor-plugin-common/src/index.ts +++ b/packages/plugins/other/visitor-plugin-common/src/index.ts @@ -21,3 +21,4 @@ export * from './utils.js'; export * from './variables-to-object.js'; export * from './convert-schema-enum-to-declaration-block-string.js'; export * from './graphql-type-utils.js'; +export { typedDocumentStringTemplate } from './typed-document-string.js'; diff --git a/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts b/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts new file mode 100644 index 00000000000..1f969d8e502 --- /dev/null +++ b/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts @@ -0,0 +1,24 @@ +/** + * `typedDocumentStringTemplate` is a utility template required by plugins + * that use documentMode=string. + * The class acts as a wrapper of string but allows it to type the string with + * GraphQL Result and Variables type. + */ +export const typedDocumentStringTemplate = `export class TypedDocumentString + extends String + implements DocumentTypeDecoration +{ + __apiType?: NonNullable['__apiType']>; + private value: string; + public __meta__?: Record | undefined; + + constructor(value: string, __meta__?: Record | undefined) { + super(value); + this.value = value; + this.__meta__ = __meta__; + } + + override toString(): string & DocumentTypeDecoration { + return this.value; + } +}`; diff --git a/packages/plugins/typescript/typed-document-node/src/index.ts b/packages/plugins/typescript/typed-document-node/src/index.ts index 5d1e156fef8..5caa8a58ad2 100644 --- a/packages/plugins/typescript/typed-document-node/src/index.ts +++ b/packages/plugins/typescript/typed-document-node/src/index.ts @@ -6,6 +6,7 @@ import { LoadedFragment, optimizeOperations, RawClientSideBasePluginConfig, + typedDocumentStringTemplate, } from '@graphql-codegen/visitor-plugin-common'; import { TypeScriptTypedDocumentNodesConfig } from './config.js'; import { TypeScriptDocumentNodesVisitor } from './visitor.js'; @@ -39,27 +40,7 @@ export const plugin: PluginFunction = ( let content: string[] = []; if (config.documentMode === DocumentMode.string) { - content = [ - `\ -export class TypedDocumentString - extends String - implements DocumentTypeDecoration -{ - __apiType?: NonNullable['__apiType']>; - private value: string; - public __meta__?: Record | undefined; - - constructor(value: string, __meta__?: Record | undefined) { - super(value); - this.value = value; - this.__meta__ = __meta__; - } - - override toString(): string & DocumentTypeDecoration { - return this.value; - } -}`, - ]; + content = [typedDocumentStringTemplate]; } return { From 99ce1a93bad6b97169ca5814e914d764c1aab487 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Tue, 2 Jun 2026 01:17:50 +1000 Subject: [PATCH 2/3] Add import util for typed-document-string helper (#10865) * Add import util for typed-document-string helper * Refactor to use typedDocumentString --- .changeset/nice-goats-beg.md | 2 +- .changeset/tricky-brooms-ring.md | 3 +- .../other/visitor-plugin-common/src/index.ts | 2 +- .../src/typed-document-string.ts | 28 +++++++++++++------ .../typed-document-node/src/index.ts | 4 +-- .../typed-document-node/src/visitor.ts | 8 ++---- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.changeset/nice-goats-beg.md b/.changeset/nice-goats-beg.md index 3f36aa8054c..760c3e35823 100644 --- a/.changeset/nice-goats-beg.md +++ b/.changeset/nice-goats-beg.md @@ -2,5 +2,5 @@ '@graphql-codegen/typed-document-node': patch --- -Use typedDocumentStringTemplate from @graphql-codegen/visitor-plugin-common instead of the inline +Use `typedDocumentString` from @graphql-codegen/visitor-plugin-common instead of the inlined version diff --git a/.changeset/tricky-brooms-ring.md b/.changeset/tricky-brooms-ring.md index 0f5b0f028a7..8c55ed79221 100644 --- a/.changeset/tricky-brooms-ring.md +++ b/.changeset/tricky-brooms-ring.md @@ -2,5 +2,4 @@ '@graphql-codegen/visitor-plugin-common': minor --- -Create typedDocumentStringTemplate to support TypedDocumentString usage (common in Client-side -plugins when documentMode=string) +Create `typedDocumentString` to support `TypedDocumentString` usage (common in Client-side plugins when documentMode=string) diff --git a/packages/plugins/other/visitor-plugin-common/src/index.ts b/packages/plugins/other/visitor-plugin-common/src/index.ts index a82f6d865c0..df4eceb2c51 100644 --- a/packages/plugins/other/visitor-plugin-common/src/index.ts +++ b/packages/plugins/other/visitor-plugin-common/src/index.ts @@ -21,4 +21,4 @@ export * from './utils.js'; export * from './variables-to-object.js'; export * from './convert-schema-enum-to-declaration-block-string.js'; export * from './graphql-type-utils.js'; -export { typedDocumentStringTemplate } from './typed-document-string.js'; +export { typedDocumentString } from './typed-document-string.js'; diff --git a/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts b/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts index 1f969d8e502..58cac2f4467 100644 --- a/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts +++ b/packages/plugins/other/visitor-plugin-common/src/typed-document-string.ts @@ -1,10 +1,10 @@ -/** - * `typedDocumentStringTemplate` is a utility template required by plugins - * that use documentMode=string. - * The class acts as a wrapper of string but allows it to type the string with - * GraphQL Result and Variables type. - */ -export const typedDocumentStringTemplate = `export class TypedDocumentString +export const typedDocumentString = { + /** + * This is a utility template required by plugins that use `documentMode=string` + * The class acts as a wrapper of string, and allows typing the string with + * GraphQL `Result` and `Variables` types. + */ + template: `export class TypedDocumentString extends String implements DocumentTypeDecoration { @@ -21,4 +21,16 @@ export const typedDocumentStringTemplate = `export class TypedDocumentString { return this.value; } -}`; +}`, + /** + * `TypedDocumentString` class above needs `DocumentTypeDecoration` from `@graphql-typed-document-node/core` + * This `imports` object helps when generating the import statement. + * + * This intentionally follows [ClientSideBaseVisitor#_generateImport()]({@link https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts}) + * to make it easier to use. + */ + import: { + moduleName: '@graphql-typed-document-node/core', + propName: 'DocumentTypeDecoration', + }, +}; diff --git a/packages/plugins/typescript/typed-document-node/src/index.ts b/packages/plugins/typescript/typed-document-node/src/index.ts index 5caa8a58ad2..5b44bbb3428 100644 --- a/packages/plugins/typescript/typed-document-node/src/index.ts +++ b/packages/plugins/typescript/typed-document-node/src/index.ts @@ -6,7 +6,7 @@ import { LoadedFragment, optimizeOperations, RawClientSideBasePluginConfig, - typedDocumentStringTemplate, + typedDocumentString, } from '@graphql-codegen/visitor-plugin-common'; import { TypeScriptTypedDocumentNodesConfig } from './config.js'; import { TypeScriptDocumentNodesVisitor } from './visitor.js'; @@ -40,7 +40,7 @@ export const plugin: PluginFunction = ( let content: string[] = []; if (config.documentMode === DocumentMode.string) { - content = [typedDocumentStringTemplate]; + content = [typedDocumentString.template]; } return { diff --git a/packages/plugins/typescript/typed-document-node/src/visitor.ts b/packages/plugins/typescript/typed-document-node/src/visitor.ts index 39bea7a28cb..4ea5eabd66f 100644 --- a/packages/plugins/typescript/typed-document-node/src/visitor.ts +++ b/packages/plugins/typescript/typed-document-node/src/visitor.ts @@ -7,6 +7,7 @@ import { DocumentMode, LoadedFragment, RawClientSideBasePluginConfig, + typedDocumentString, } from '@graphql-codegen/visitor-plugin-common'; interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePluginConfig { @@ -50,11 +51,8 @@ export class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor< this._imports.add(tagImport); } else if (this.config.documentMode === DocumentMode.string) { const tagImport = this._generateImport( - { - moduleName: '@graphql-typed-document-node/core', - propName: 'DocumentTypeDecoration', - }, - 'DocumentTypeDecoration', + typedDocumentString.import, + typedDocumentString.import.propName, true, ); this._imports.add(tagImport); From df7a61074ea49c45be79311dc61e0c8840089abe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 2 Jun 2026 01:27:23 +1000 Subject: [PATCH 3/3] chore(release): update monorepo packages versions (#10864) Co-authored-by: github-actions[bot] --- .changeset/nice-goats-beg.md | 6 ------ .changeset/tricky-brooms-ring.md | 5 ----- .../plugins/other/visitor-plugin-common/CHANGELOG.md | 9 +++++++++ .../plugins/other/visitor-plugin-common/package.json | 2 +- .../typescript/typed-document-node/CHANGELOG.md | 12 ++++++++++++ .../typescript/typed-document-node/package.json | 2 +- 6 files changed, 23 insertions(+), 13 deletions(-) delete mode 100644 .changeset/nice-goats-beg.md delete mode 100644 .changeset/tricky-brooms-ring.md diff --git a/.changeset/nice-goats-beg.md b/.changeset/nice-goats-beg.md deleted file mode 100644 index 760c3e35823..00000000000 --- a/.changeset/nice-goats-beg.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@graphql-codegen/typed-document-node': patch ---- - -Use `typedDocumentString` from @graphql-codegen/visitor-plugin-common instead of the inlined -version diff --git a/.changeset/tricky-brooms-ring.md b/.changeset/tricky-brooms-ring.md deleted file mode 100644 index 8c55ed79221..00000000000 --- a/.changeset/tricky-brooms-ring.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': minor ---- - -Create `typedDocumentString` to support `TypedDocumentString` usage (common in Client-side plugins when documentMode=string) diff --git a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md index fd440507b70..de7ecb05dde 100644 --- a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md +++ b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md @@ -1,5 +1,14 @@ # @graphql-codegen/visitor-plugin-common +## 7.1.0 + +### Minor Changes + +- [#10863](https://github.com/dotansimha/graphql-code-generator/pull/10863) + [`8707247`](https://github.com/dotansimha/graphql-code-generator/commit/8707247857ecd77aaed6930b9eb6985323350932) + Thanks [@eddeee888](https://github.com/eddeee888)! - Create `typedDocumentString` to support + `TypedDocumentString` usage (common in Client-side plugins when documentMode=string) + ## 7.0.4 ### Patch Changes diff --git a/packages/plugins/other/visitor-plugin-common/package.json b/packages/plugins/other/visitor-plugin-common/package.json index c74349e4e43..5e3e5d1509d 100644 --- a/packages/plugins/other/visitor-plugin-common/package.json +++ b/packages/plugins/other/visitor-plugin-common/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/visitor-plugin-common", - "version": "7.0.4", + "version": "7.1.0", "type": "module", "repository": { "type": "git", diff --git a/packages/plugins/typescript/typed-document-node/CHANGELOG.md b/packages/plugins/typescript/typed-document-node/CHANGELOG.md index 8d4d37e8843..ecf9ce8a1a6 100644 --- a/packages/plugins/typescript/typed-document-node/CHANGELOG.md +++ b/packages/plugins/typescript/typed-document-node/CHANGELOG.md @@ -1,5 +1,17 @@ # @graphql-codegen/typed-document-node +## 7.0.3 + +### Patch Changes + +- [#10863](https://github.com/dotansimha/graphql-code-generator/pull/10863) + [`8707247`](https://github.com/dotansimha/graphql-code-generator/commit/8707247857ecd77aaed6930b9eb6985323350932) + Thanks [@eddeee888](https://github.com/eddeee888)! - Use `typedDocumentString` from + @graphql-codegen/visitor-plugin-common instead of the inlined version +- Updated dependencies + [[`8707247`](https://github.com/dotansimha/graphql-code-generator/commit/8707247857ecd77aaed6930b9eb6985323350932)]: + - @graphql-codegen/visitor-plugin-common@7.1.0 + ## 7.0.2 ### Patch Changes diff --git a/packages/plugins/typescript/typed-document-node/package.json b/packages/plugins/typescript/typed-document-node/package.json index 4219ad4330b..831313c1fd2 100644 --- a/packages/plugins/typescript/typed-document-node/package.json +++ b/packages/plugins/typescript/typed-document-node/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typed-document-node", - "version": "7.0.2", + "version": "7.0.3", "type": "module", "description": "GraphQL Code Generator plugin for generating ready-to-use TypedDocumentNode based on GraphQL operations", "repository": {