Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/plugins/other/visitor-plugin-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/other/visitor-plugin-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "7.0.4",
"version": "7.1.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/other/visitor-plugin-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { typedDocumentString } from './typed-document-string.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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<TResult, TVariables>
extends String
implements DocumentTypeDecoration<TResult, TVariables>
{
__apiType?: NonNullable<DocumentTypeDecoration<TResult, TVariables>['__apiType']>;
private value: string;
public __meta__?: Record<string, any> | undefined;

constructor(value: string, __meta__?: Record<string, any> | undefined) {
super(value);
this.value = value;
this.__meta__ = __meta__;
}

override toString(): string & DocumentTypeDecoration<TResult, TVariables> {
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',
},
};
12 changes: 12 additions & 0 deletions packages/plugins/typescript/typed-document-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
23 changes: 2 additions & 21 deletions packages/plugins/typescript/typed-document-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LoadedFragment,
optimizeOperations,
RawClientSideBasePluginConfig,
typedDocumentString,
} from '@graphql-codegen/visitor-plugin-common';
import { TypeScriptTypedDocumentNodesConfig } from './config.js';
import { TypeScriptDocumentNodesVisitor } from './visitor.js';
Expand Down Expand Up @@ -39,27 +40,7 @@ export const plugin: PluginFunction<TypeScriptTypedDocumentNodesConfig> = (

let content: string[] = [];
if (config.documentMode === DocumentMode.string) {
content = [
`\
export class TypedDocumentString<TResult, TVariables>
extends String
implements DocumentTypeDecoration<TResult, TVariables>
{
__apiType?: NonNullable<DocumentTypeDecoration<TResult, TVariables>['__apiType']>;
private value: string;
public __meta__?: Record<string, any> | undefined;

constructor(value: string, __meta__?: Record<string, any> | undefined) {
super(value);
this.value = value;
this.__meta__ = __meta__;
}

override toString(): string & DocumentTypeDecoration<TResult, TVariables> {
return this.value;
}
}`,
];
content = [typedDocumentString.template];
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DocumentMode,
LoadedFragment,
RawClientSideBasePluginConfig,
typedDocumentString,
} from '@graphql-codegen/visitor-plugin-common';

interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePluginConfig {
Expand Down Expand Up @@ -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);
Expand Down
Loading