@graphql-codegen/typescript-react-query 5.0.0-alpha-20230524114330-5ff6385cd → 5.0.0-alpha-20230524165521-e9c8bb8f4
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/variables-generator.js +9 -1
- package/cjs/visitor.js +7 -0
- package/esm/variables-generator.js +6 -0
- package/esm/visitor.js +8 -1
- package/package.json +2 -2
- package/typings/config.d.cts +11 -0
- package/typings/config.d.ts +11 -0
- package/typings/variables-generator.d.cts +2 -0
- package/typings/variables-generator.d.ts +2 -0
- package/typings/visitor.d.cts +1 -0
- package/typings/visitor.d.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateMutationKeyMaker = exports.generateMutationKey = exports.generateQueryKeyMaker = exports.generateQueryKey = exports.generateInfiniteQueryKeyMaker = exports.generateInfiniteQueryKey = exports.generateQueryVariablesSignature = void 0;
|
|
3
|
+
exports.generateMutationKeyMaker = exports.generateMutationKey = exports.generateQueryRootKeyMaker = exports.generateQueryKeyMaker = exports.generateQueryKey = exports.generateInfiniteQueryRootKeyMaker = exports.generateInfiniteQueryKeyMaker = exports.generateInfiniteQueryKey = exports.generateQueryVariablesSignature = void 0;
|
|
4
4
|
function generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes) {
|
|
5
5
|
return `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
6
6
|
}
|
|
@@ -16,6 +16,10 @@ function generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTy
|
|
|
16
16
|
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
17
17
|
}
|
|
18
18
|
exports.generateInfiniteQueryKeyMaker = generateInfiniteQueryKeyMaker;
|
|
19
|
+
function generateInfiniteQueryRootKeyMaker(node, operationName) {
|
|
20
|
+
return `\nuseInfinite${operationName}.rootKey = '${node.name.value}.infinite';\n`;
|
|
21
|
+
}
|
|
22
|
+
exports.generateInfiniteQueryRootKeyMaker = generateInfiniteQueryRootKeyMaker;
|
|
19
23
|
function generateQueryKey(node, hasRequiredVariables) {
|
|
20
24
|
if (hasRequiredVariables)
|
|
21
25
|
return `['${node.name.value}', variables]`;
|
|
@@ -27,6 +31,10 @@ function generateQueryKeyMaker(node, operationName, operationVariablesTypes, has
|
|
|
27
31
|
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
28
32
|
}
|
|
29
33
|
exports.generateQueryKeyMaker = generateQueryKeyMaker;
|
|
34
|
+
function generateQueryRootKeyMaker(node, operationName) {
|
|
35
|
+
return `\nuse${operationName}.rootKey = '${node.name.value}';\n`;
|
|
36
|
+
}
|
|
37
|
+
exports.generateQueryRootKeyMaker = generateQueryRootKeyMaker;
|
|
30
38
|
function generateMutationKey(node) {
|
|
31
39
|
return `['${node.name.value}']`;
|
|
32
40
|
}
|
package/cjs/visitor.js
CHANGED
|
@@ -17,6 +17,7 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
|
|
|
17
17
|
errorType: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.errorType, 'unknown'),
|
|
18
18
|
exposeDocument: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeDocument, false),
|
|
19
19
|
exposeQueryKeys: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeQueryKeys, false),
|
|
20
|
+
exposeQueryRootKeys: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeQueryRootKeys, false),
|
|
20
21
|
exposeMutationKeys: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeMutationKeys, false),
|
|
21
22
|
exposeFetcher: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeFetcher, false),
|
|
22
23
|
addInfiniteQuery: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.addInfiniteQuery, false),
|
|
@@ -110,11 +111,17 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
|
|
|
110
111
|
if (this.config.exposeQueryKeys) {
|
|
111
112
|
query += `\n${(0, variables_generator_js_1.generateQueryKeyMaker)(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
112
113
|
}
|
|
114
|
+
if (this.config.exposeQueryRootKeys) {
|
|
115
|
+
query += `\n${(0, variables_generator_js_1.generateQueryRootKeyMaker)(node, operationName)}`;
|
|
116
|
+
}
|
|
113
117
|
if (this.config.addInfiniteQuery) {
|
|
114
118
|
query += `\n${this.fetcher.generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables)}\n`;
|
|
115
119
|
if (this.config.exposeQueryKeys) {
|
|
116
120
|
query += `\n${(0, variables_generator_js_1.generateInfiniteQueryKeyMaker)(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
117
121
|
}
|
|
122
|
+
if (this.config.exposeQueryRootKeys) {
|
|
123
|
+
query += `\n${(0, variables_generator_js_1.generateInfiniteQueryRootKeyMaker)(node, operationName)}`;
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
120
127
|
// is to prevent calling generateFetcherFetch for each query since all the queries won't be able to generate
|
|
@@ -10,6 +10,9 @@ export function generateInfiniteQueryKeyMaker(node, operationName, operationVari
|
|
|
10
10
|
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
11
11
|
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
12
12
|
}
|
|
13
|
+
export function generateInfiniteQueryRootKeyMaker(node, operationName) {
|
|
14
|
+
return `\nuseInfinite${operationName}.rootKey = '${node.name.value}.infinite';\n`;
|
|
15
|
+
}
|
|
13
16
|
export function generateQueryKey(node, hasRequiredVariables) {
|
|
14
17
|
if (hasRequiredVariables)
|
|
15
18
|
return `['${node.name.value}', variables]`;
|
|
@@ -19,6 +22,9 @@ export function generateQueryKeyMaker(node, operationName, operationVariablesTyp
|
|
|
19
22
|
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
20
23
|
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
21
24
|
}
|
|
25
|
+
export function generateQueryRootKeyMaker(node, operationName) {
|
|
26
|
+
return `\nuse${operationName}.rootKey = '${node.name.value}';\n`;
|
|
27
|
+
}
|
|
22
28
|
export function generateMutationKey(node) {
|
|
23
29
|
return `['${node.name.value}']`;
|
|
24
30
|
}
|
package/esm/visitor.js
CHANGED
|
@@ -5,7 +5,7 @@ import { CustomMapperFetcher } from './fetcher-custom-mapper.js';
|
|
|
5
5
|
import { HardcodedFetchFetcher } from './fetcher-fetch-hardcoded.js';
|
|
6
6
|
import { FetchFetcher } from './fetcher-fetch.js';
|
|
7
7
|
import { GraphQLRequestClientFetcher } from './fetcher-graphql-request.js';
|
|
8
|
-
import { generateInfiniteQueryKeyMaker, generateMutationKeyMaker, generateQueryKeyMaker, } from './variables-generator.js';
|
|
8
|
+
import { generateInfiniteQueryKeyMaker, generateInfiniteQueryRootKeyMaker, generateMutationKeyMaker, generateQueryKeyMaker, generateQueryRootKeyMaker, } from './variables-generator.js';
|
|
9
9
|
export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
10
10
|
constructor(schema, fragments, rawConfig, documents) {
|
|
11
11
|
super(schema, fragments, rawConfig, {
|
|
@@ -13,6 +13,7 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
13
13
|
errorType: getConfigValue(rawConfig.errorType, 'unknown'),
|
|
14
14
|
exposeDocument: getConfigValue(rawConfig.exposeDocument, false),
|
|
15
15
|
exposeQueryKeys: getConfigValue(rawConfig.exposeQueryKeys, false),
|
|
16
|
+
exposeQueryRootKeys: getConfigValue(rawConfig.exposeQueryRootKeys, false),
|
|
16
17
|
exposeMutationKeys: getConfigValue(rawConfig.exposeMutationKeys, false),
|
|
17
18
|
exposeFetcher: getConfigValue(rawConfig.exposeFetcher, false),
|
|
18
19
|
addInfiniteQuery: getConfigValue(rawConfig.addInfiniteQuery, false),
|
|
@@ -106,11 +107,17 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
106
107
|
if (this.config.exposeQueryKeys) {
|
|
107
108
|
query += `\n${generateQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
108
109
|
}
|
|
110
|
+
if (this.config.exposeQueryRootKeys) {
|
|
111
|
+
query += `\n${generateQueryRootKeyMaker(node, operationName)}`;
|
|
112
|
+
}
|
|
109
113
|
if (this.config.addInfiniteQuery) {
|
|
110
114
|
query += `\n${this.fetcher.generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables)}\n`;
|
|
111
115
|
if (this.config.exposeQueryKeys) {
|
|
112
116
|
query += `\n${generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
113
117
|
}
|
|
118
|
+
if (this.config.exposeQueryRootKeys) {
|
|
119
|
+
query += `\n${generateInfiniteQueryRootKeyMaker(node, operationName)}`;
|
|
120
|
+
}
|
|
114
121
|
}
|
|
115
122
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
116
123
|
// is to prevent calling generateFetcherFetch for each query since all the queries won't be able to generate
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "5.0.0-alpha-
|
|
3
|
+
"version": "5.0.0-alpha-20230524165521-e9c8bb8f4",
|
|
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"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@graphql-codegen/visitor-plugin-common": "2.13.1",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.15",
|
|
13
|
-
"tslib": "~2.
|
|
13
|
+
"tslib": "~2.5.0"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
package/typings/config.d.cts
CHANGED
|
@@ -51,6 +51,17 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
exposeQueryKeys?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* @default false
|
|
56
|
+
* @description For each generate query hook adds rootKey. Useful for cache updates.
|
|
57
|
+
* @exampleMarkdown
|
|
58
|
+
* ```ts
|
|
59
|
+
* const query = useUserDetailsQuery(...)
|
|
60
|
+
* const key = useUserDetailsQuery.rootKey
|
|
61
|
+
* // use key in a cache update after a mutation
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
exposeQueryRootKeys?: boolean;
|
|
54
65
|
/**
|
|
55
66
|
* @default false
|
|
56
67
|
* @description For each generate mutation hook adds getKey() function. Useful for call outside of functional component.
|
package/typings/config.d.ts
CHANGED
|
@@ -51,6 +51,17 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
exposeQueryKeys?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* @default false
|
|
56
|
+
* @description For each generate query hook adds rootKey. Useful for cache updates.
|
|
57
|
+
* @exampleMarkdown
|
|
58
|
+
* ```ts
|
|
59
|
+
* const query = useUserDetailsQuery(...)
|
|
60
|
+
* const key = useUserDetailsQuery.rootKey
|
|
61
|
+
* // use key in a cache update after a mutation
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
exposeQueryRootKeys?: boolean;
|
|
54
65
|
/**
|
|
55
66
|
* @default false
|
|
56
67
|
* @description For each generate mutation hook adds getKey() function. Useful for call outside of functional component.
|
|
@@ -2,7 +2,9 @@ import { OperationDefinitionNode } from 'graphql';
|
|
|
2
2
|
export declare function generateQueryVariablesSignature(hasRequiredVariables: boolean, operationVariablesTypes: string): string;
|
|
3
3
|
export declare function generateInfiniteQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
4
4
|
export declare function generateInfiniteQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
5
|
+
export declare function generateInfiniteQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
5
6
|
export declare function generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
6
7
|
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
8
|
+
export declare function generateQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
7
9
|
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|
|
8
10
|
export declare function generateMutationKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
@@ -2,7 +2,9 @@ import { OperationDefinitionNode } from 'graphql';
|
|
|
2
2
|
export declare function generateQueryVariablesSignature(hasRequiredVariables: boolean, operationVariablesTypes: string): string;
|
|
3
3
|
export declare function generateInfiniteQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
4
4
|
export declare function generateInfiniteQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
5
|
+
export declare function generateInfiniteQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
5
6
|
export declare function generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
6
7
|
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
8
|
+
export declare function generateQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
7
9
|
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|
|
8
10
|
export declare function generateMutationKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
package/typings/visitor.d.cts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
|
|
|
7
7
|
errorType: string;
|
|
8
8
|
exposeDocument: boolean;
|
|
9
9
|
exposeQueryKeys: boolean;
|
|
10
|
+
exposeQueryRootKeys: boolean;
|
|
10
11
|
exposeMutationKeys: boolean;
|
|
11
12
|
exposeFetcher: boolean;
|
|
12
13
|
addInfiniteQuery: boolean;
|
package/typings/visitor.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
|
|
|
7
7
|
errorType: string;
|
|
8
8
|
exposeDocument: boolean;
|
|
9
9
|
exposeQueryKeys: boolean;
|
|
10
|
+
exposeQueryRootKeys: boolean;
|
|
10
11
|
exposeMutationKeys: boolean;
|
|
11
12
|
exposeFetcher: boolean;
|
|
12
13
|
addInfiniteQuery: boolean;
|