@graphql-codegen/typescript-react-query 7.0.3 → 7.0.4-alpha-20260618140500-86f8be40e600a0e874729c3725269ffca9d6ad90
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 +12 -6
- package/cjs/visitor.js +19 -17
- package/esm/index.js +12 -6
- package/esm/visitor.js +19 -17
- package/package.json +2 -2
- package/typings/visitor.d.cts +1 -0
- package/typings/visitor.d.ts +1 -0
package/cjs/index.js
CHANGED
|
@@ -20,6 +20,14 @@ const plugin = (schema, documents, config) => {
|
|
|
20
20
|
];
|
|
21
21
|
const visitor = new visitor_js_1.ReactQueryVisitor(schema, allFragments, config, documents);
|
|
22
22
|
const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
|
|
23
|
+
const prepend = [...visitor.getImports()];
|
|
24
|
+
const content = [''];
|
|
25
|
+
if (visitor.hasOperations) {
|
|
26
|
+
prepend.push(visitor.getFetcherImplementation());
|
|
27
|
+
}
|
|
28
|
+
if (visitor.hasFragments) {
|
|
29
|
+
content.push(visitor_plugin_common_1.typedDocumentString.template);
|
|
30
|
+
}
|
|
23
31
|
if (visitor.hasOperations) {
|
|
24
32
|
return {
|
|
25
33
|
prepend: [...visitor.getImports(), visitor.getFetcherImplementation()],
|
|
@@ -31,13 +39,11 @@ const plugin = (schema, documents, config) => {
|
|
|
31
39
|
].join('\n'),
|
|
32
40
|
};
|
|
33
41
|
}
|
|
42
|
+
content.push(visitor.fragments);
|
|
43
|
+
content.push(...visitorResult.definitions.filter(t => typeof t === 'string'));
|
|
34
44
|
return {
|
|
35
|
-
prepend
|
|
36
|
-
content:
|
|
37
|
-
'',
|
|
38
|
-
visitor.fragments,
|
|
39
|
-
...visitorResult.definitions.filter(t => typeof t === 'string'),
|
|
40
|
-
].join('\n'),
|
|
45
|
+
prepend,
|
|
46
|
+
content: content.join('\n'),
|
|
41
47
|
};
|
|
42
48
|
};
|
|
43
49
|
exports.plugin = plugin;
|
package/cjs/visitor.js
CHANGED
|
@@ -53,26 +53,28 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
|
|
|
53
53
|
get hasOperations() {
|
|
54
54
|
return this._collectedOperations.length > 0;
|
|
55
55
|
}
|
|
56
|
+
get hasFragments() {
|
|
57
|
+
return this._fragments.size > 0;
|
|
58
|
+
}
|
|
56
59
|
getImports() {
|
|
57
60
|
const baseImports = super.getImports();
|
|
58
|
-
if (
|
|
59
|
-
|
|
61
|
+
if (this.hasFragments || this.hasOperations) {
|
|
62
|
+
const typedDocumentStringPropImport = this._generateImport(visitor_plugin_common_1.typedDocumentString.import, visitor_plugin_common_1.typedDocumentString.import.propName, true);
|
|
63
|
+
baseImports.push(typedDocumentStringPropImport);
|
|
64
|
+
}
|
|
65
|
+
if (this.hasOperations) {
|
|
66
|
+
const hookAndTypeImports = [
|
|
67
|
+
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
68
|
+
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
69
|
+
];
|
|
70
|
+
const moduleName = this.config.reactQueryImportFrom
|
|
71
|
+
? this.config.reactQueryImportFrom
|
|
72
|
+
: this.config.reactQueryVersion <= 3
|
|
73
|
+
? 'react-query'
|
|
74
|
+
: '@tanstack/react-query';
|
|
75
|
+
baseImports.push(`import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`);
|
|
60
76
|
}
|
|
61
|
-
|
|
62
|
-
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
63
|
-
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
64
|
-
];
|
|
65
|
-
const moduleName = this.config.reactQueryImportFrom
|
|
66
|
-
? this.config.reactQueryImportFrom
|
|
67
|
-
: this.config.reactQueryVersion <= 3
|
|
68
|
-
? 'react-query'
|
|
69
|
-
: '@tanstack/react-query';
|
|
70
|
-
const typedDocumentStringPropImport = this._generateImport(visitor_plugin_common_1.typedDocumentString.import, visitor_plugin_common_1.typedDocumentString.import.propName, true);
|
|
71
|
-
return [
|
|
72
|
-
...baseImports,
|
|
73
|
-
typedDocumentStringPropImport,
|
|
74
|
-
`import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`,
|
|
75
|
-
];
|
|
77
|
+
return baseImports;
|
|
76
78
|
}
|
|
77
79
|
getFetcherImplementation() {
|
|
78
80
|
return this.fetcher.generateFetcherImplementation();
|
package/esm/index.js
CHANGED
|
@@ -16,6 +16,14 @@ export const plugin = (schema, documents, config) => {
|
|
|
16
16
|
];
|
|
17
17
|
const visitor = new ReactQueryVisitor(schema, allFragments, config, documents);
|
|
18
18
|
const visitorResult = oldVisit(allAst, { leave: visitor });
|
|
19
|
+
const prepend = [...visitor.getImports()];
|
|
20
|
+
const content = [''];
|
|
21
|
+
if (visitor.hasOperations) {
|
|
22
|
+
prepend.push(visitor.getFetcherImplementation());
|
|
23
|
+
}
|
|
24
|
+
if (visitor.hasFragments) {
|
|
25
|
+
content.push(typedDocumentString.template);
|
|
26
|
+
}
|
|
19
27
|
if (visitor.hasOperations) {
|
|
20
28
|
return {
|
|
21
29
|
prepend: [...visitor.getImports(), visitor.getFetcherImplementation()],
|
|
@@ -27,13 +35,11 @@ export const plugin = (schema, documents, config) => {
|
|
|
27
35
|
].join('\n'),
|
|
28
36
|
};
|
|
29
37
|
}
|
|
38
|
+
content.push(visitor.fragments);
|
|
39
|
+
content.push(...visitorResult.definitions.filter(t => typeof t === 'string'));
|
|
30
40
|
return {
|
|
31
|
-
prepend
|
|
32
|
-
content:
|
|
33
|
-
'',
|
|
34
|
-
visitor.fragments,
|
|
35
|
-
...visitorResult.definitions.filter(t => typeof t === 'string'),
|
|
36
|
-
].join('\n'),
|
|
41
|
+
prepend,
|
|
42
|
+
content: content.join('\n'),
|
|
37
43
|
};
|
|
38
44
|
};
|
|
39
45
|
export const validate = async (schema, documents, config, outputFile) => {
|
package/esm/visitor.js
CHANGED
|
@@ -49,26 +49,28 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
49
49
|
get hasOperations() {
|
|
50
50
|
return this._collectedOperations.length > 0;
|
|
51
51
|
}
|
|
52
|
+
get hasFragments() {
|
|
53
|
+
return this._fragments.size > 0;
|
|
54
|
+
}
|
|
52
55
|
getImports() {
|
|
53
56
|
const baseImports = super.getImports();
|
|
54
|
-
if (
|
|
55
|
-
|
|
57
|
+
if (this.hasFragments || this.hasOperations) {
|
|
58
|
+
const typedDocumentStringPropImport = this._generateImport(typedDocumentString.import, typedDocumentString.import.propName, true);
|
|
59
|
+
baseImports.push(typedDocumentStringPropImport);
|
|
60
|
+
}
|
|
61
|
+
if (this.hasOperations) {
|
|
62
|
+
const hookAndTypeImports = [
|
|
63
|
+
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
64
|
+
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
65
|
+
];
|
|
66
|
+
const moduleName = this.config.reactQueryImportFrom
|
|
67
|
+
? this.config.reactQueryImportFrom
|
|
68
|
+
: this.config.reactQueryVersion <= 3
|
|
69
|
+
? 'react-query'
|
|
70
|
+
: '@tanstack/react-query';
|
|
71
|
+
baseImports.push(`import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`);
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
59
|
-
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
60
|
-
];
|
|
61
|
-
const moduleName = this.config.reactQueryImportFrom
|
|
62
|
-
? this.config.reactQueryImportFrom
|
|
63
|
-
: this.config.reactQueryVersion <= 3
|
|
64
|
-
? 'react-query'
|
|
65
|
-
: '@tanstack/react-query';
|
|
66
|
-
const typedDocumentStringPropImport = this._generateImport(typedDocumentString.import, typedDocumentString.import.propName, true);
|
|
67
|
-
return [
|
|
68
|
-
...baseImports,
|
|
69
|
-
typedDocumentStringPropImport,
|
|
70
|
-
`import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`,
|
|
71
|
-
];
|
|
73
|
+
return baseImports;
|
|
72
74
|
}
|
|
73
75
|
getFetcherImplementation() {
|
|
74
76
|
return this.fetcher.generateFetcherImplementation();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4-alpha-20260618140500-86f8be40e600a0e874729c3725269ffca9d6ad90",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a ready-to-use React-Query Hooks 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
|
"@graphql-codegen/plugin-helpers": "^7.0.1",
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "^7.1.
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "^7.1.1",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.15",
|
|
13
13
|
"tslib": "^2.8.1"
|
package/typings/visitor.d.cts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryR
|
|
|
14
14
|
get imports(): Set<string>;
|
|
15
15
|
private createFetcher;
|
|
16
16
|
get hasOperations(): boolean;
|
|
17
|
+
get hasFragments(): boolean;
|
|
17
18
|
getImports(): string[];
|
|
18
19
|
getFetcherImplementation(): string;
|
|
19
20
|
private _getHookSuffix;
|
package/typings/visitor.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryR
|
|
|
14
14
|
get imports(): Set<string>;
|
|
15
15
|
private createFetcher;
|
|
16
16
|
get hasOperations(): boolean;
|
|
17
|
+
get hasFragments(): boolean;
|
|
17
18
|
getImports(): string[];
|
|
18
19
|
getFetcherImplementation(): string;
|
|
19
20
|
private _getHookSuffix;
|