@graphql-codegen/typed-document-node 3.1.0-alpha-20230313193142-2c6ee68d6 → 3.1.0-alpha-20230314135103-4e732da2e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +21 -1
- package/cjs/visitor.js +1 -1
- package/esm/index.js +22 -2
- package/esm/visitor.js +1 -1
- package/package.json +2 -2
package/cjs/index.js
CHANGED
|
@@ -20,9 +20,29 @@ const plugin = (schema, rawDocuments, config) => {
|
|
|
20
20
|
];
|
|
21
21
|
const visitor = new visitor_js_1.TypeScriptDocumentNodesVisitor(schema, allFragments, config, documents);
|
|
22
22
|
const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
|
|
23
|
+
let content = [];
|
|
24
|
+
if (config.documentMode === visitor_plugin_common_1.DocumentMode.string) {
|
|
25
|
+
content = [
|
|
26
|
+
`\
|
|
27
|
+
export class TypedDocumentString<TResult, TVariables>
|
|
28
|
+
extends String
|
|
29
|
+
implements DocumentTypeDecoration<TResult, TVariables>
|
|
30
|
+
{
|
|
31
|
+
__apiType?: DocumentTypeDecoration<TResult, TVariables>['__apiType'];
|
|
32
|
+
|
|
33
|
+
constructor(private value: string, public __meta__?: { hash: string }) {
|
|
34
|
+
super(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
toString(): string & DocumentTypeDecoration<TResult, TVariables> {
|
|
38
|
+
return this.value;
|
|
39
|
+
}
|
|
40
|
+
}`,
|
|
41
|
+
];
|
|
42
|
+
}
|
|
23
43
|
return {
|
|
24
44
|
prepend: allAst.definitions.length === 0 ? [] : visitor.getImports(),
|
|
25
|
-
content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
|
|
45
|
+
content: [...content, visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
|
|
26
46
|
};
|
|
27
47
|
};
|
|
28
48
|
exports.plugin = plugin;
|
package/cjs/visitor.js
CHANGED
|
@@ -20,7 +20,7 @@ class TypeScriptDocumentNodesVisitor extends visitor_plugin_common_1.ClientSideB
|
|
|
20
20
|
this._imports.add(tagImport);
|
|
21
21
|
}
|
|
22
22
|
else if (this.config.documentMode === visitor_plugin_common_1.DocumentMode.string) {
|
|
23
|
-
const tagImport = this._generateImport({ moduleName: '@graphql-typed-document-node/core', propName: '
|
|
23
|
+
const tagImport = this._generateImport({ moduleName: '@graphql-typed-document-node/core', propName: 'DocumentTypeDecoration' }, 'DocumentTypeDecoration', true);
|
|
24
24
|
this._imports.add(tagImport);
|
|
25
25
|
}
|
|
26
26
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extname } from 'path';
|
|
2
2
|
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
3
|
-
import { optimizeOperations, } from '@graphql-codegen/visitor-plugin-common';
|
|
3
|
+
import { DocumentMode, optimizeOperations, } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
import { concatAST, Kind } from 'graphql';
|
|
5
5
|
import { TypeScriptDocumentNodesVisitor } from './visitor.js';
|
|
6
6
|
export const plugin = (schema, rawDocuments, config) => {
|
|
@@ -17,9 +17,29 @@ export const plugin = (schema, rawDocuments, config) => {
|
|
|
17
17
|
];
|
|
18
18
|
const visitor = new TypeScriptDocumentNodesVisitor(schema, allFragments, config, documents);
|
|
19
19
|
const visitorResult = oldVisit(allAst, { leave: visitor });
|
|
20
|
+
let content = [];
|
|
21
|
+
if (config.documentMode === DocumentMode.string) {
|
|
22
|
+
content = [
|
|
23
|
+
`\
|
|
24
|
+
export class TypedDocumentString<TResult, TVariables>
|
|
25
|
+
extends String
|
|
26
|
+
implements DocumentTypeDecoration<TResult, TVariables>
|
|
27
|
+
{
|
|
28
|
+
__apiType?: DocumentTypeDecoration<TResult, TVariables>['__apiType'];
|
|
29
|
+
|
|
30
|
+
constructor(private value: string, public __meta__?: { hash: string }) {
|
|
31
|
+
super(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
toString(): string & DocumentTypeDecoration<TResult, TVariables> {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
}`,
|
|
38
|
+
];
|
|
39
|
+
}
|
|
20
40
|
return {
|
|
21
41
|
prepend: allAst.definitions.length === 0 ? [] : visitor.getImports(),
|
|
22
|
-
content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
|
|
42
|
+
content: [...content, visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
|
|
23
43
|
};
|
|
24
44
|
};
|
|
25
45
|
export const validate = async (_schema, _documents, _config, outputFile) => {
|
package/esm/visitor.js
CHANGED
|
@@ -16,7 +16,7 @@ export class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor {
|
|
|
16
16
|
this._imports.add(tagImport);
|
|
17
17
|
}
|
|
18
18
|
else if (this.config.documentMode === DocumentMode.string) {
|
|
19
|
-
const tagImport = this._generateImport({ moduleName: '@graphql-typed-document-node/core', propName: '
|
|
19
|
+
const tagImport = this._generateImport({ moduleName: '@graphql-typed-document-node/core', propName: 'DocumentTypeDecoration' }, 'DocumentTypeDecoration', true);
|
|
20
20
|
this._imports.add(tagImport);
|
|
21
21
|
}
|
|
22
22
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typed-document-node",
|
|
3
|
-
"version": "3.1.0-alpha-
|
|
3
|
+
"version": "3.1.0-alpha-20230314135103-4e732da2e",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating ready-to-use TypedDocumentNode based on GraphQL operations",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"change-case-all": "1.0.15",
|
|
10
|
-
"@graphql-codegen/plugin-helpers": "4.1.1-alpha-
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "4.1.1-alpha-20230314135103-4e732da2e",
|
|
11
11
|
"@graphql-codegen/visitor-plugin-common": "3.0.2",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
13
13
|
"tslib": "~2.5.0"
|