@graphql-codegen/typescript-react-query 3.2.4-alpha-6cdbcf02e.0 → 3.4.0
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/config.d.ts +1 -1
- package/index.js +14 -5
- package/index.mjs +14 -5
- package/package.json +3 -3
- package/variables-generator.d.ts +1 -0
package/config.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
40
40
|
exposeDocument?: boolean;
|
|
41
41
|
/**
|
|
42
42
|
* @default false
|
|
43
|
-
* @description For each generate query hook adds getKey(variables: QueryVariables) function. Useful for cache updates.
|
|
43
|
+
* @description For each generate query hook adds getKey(variables: QueryVariables) function. Useful for cache updates. If addInfiniteQuery is true, it will also add a getKey function to each infinite query.
|
|
44
44
|
* @exampleMarkdown
|
|
45
45
|
* ```ts
|
|
46
46
|
* const query = useUserDetailsQuery(...)
|
package/index.js
CHANGED
|
@@ -19,6 +19,10 @@ function generateInfiniteQueryKey(node, hasRequiredVariables) {
|
|
|
19
19
|
return `['${node.name.value}.infinite', variables]`;
|
|
20
20
|
return `variables === undefined ? ['${node.name.value}.infinite'] : ['${node.name.value}.infinite', variables]`;
|
|
21
21
|
}
|
|
22
|
+
function generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
23
|
+
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
24
|
+
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
25
|
+
}
|
|
22
26
|
function generateQueryKey(node, hasRequiredVariables) {
|
|
23
27
|
if (hasRequiredVariables)
|
|
24
28
|
return `['${node.name.value}', variables]`;
|
|
@@ -29,7 +33,7 @@ function generateQueryKeyMaker(node, operationName, operationVariablesTypes, has
|
|
|
29
33
|
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
30
34
|
}
|
|
31
35
|
function generateMutationKey(node) {
|
|
32
|
-
return `'${node.name.value}'`;
|
|
36
|
+
return `['${node.name.value}']`;
|
|
33
37
|
}
|
|
34
38
|
function generateMutationKeyMaker(node, operationName) {
|
|
35
39
|
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
@@ -65,8 +69,9 @@ class CustomMapperFetcher {
|
|
|
65
69
|
this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
66
70
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
67
71
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
72
|
+
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
68
73
|
const impl = this._isReactHook
|
|
69
|
-
? `(metaData) =>
|
|
74
|
+
? `(metaData) => query({...variables, ...(metaData.pageParam ?? {})})`
|
|
70
75
|
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ?? {})})()`;
|
|
71
76
|
return `export const useInfinite${operationName} = <
|
|
72
77
|
TData = ${operationResultType},
|
|
@@ -74,12 +79,13 @@ class CustomMapperFetcher {
|
|
|
74
79
|
>(
|
|
75
80
|
${variables},
|
|
76
81
|
${options}
|
|
77
|
-
) =>
|
|
78
|
-
${
|
|
82
|
+
) =>{
|
|
83
|
+
${implHookOuter}
|
|
84
|
+
return ${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
79
85
|
${generateInfiniteQueryKey(node, hasRequiredVariables)},
|
|
80
86
|
${impl},
|
|
81
87
|
options
|
|
82
|
-
);`;
|
|
88
|
+
)};`;
|
|
83
89
|
}
|
|
84
90
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
85
91
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
@@ -514,6 +520,9 @@ class ReactQueryVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
514
520
|
}
|
|
515
521
|
if (this.config.addInfiniteQuery) {
|
|
516
522
|
query += `\n${this.fetcher.generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables)}\n`;
|
|
523
|
+
if (this.config.exposeQueryKeys) {
|
|
524
|
+
query += `\n${generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
525
|
+
}
|
|
517
526
|
}
|
|
518
527
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
519
528
|
// is to prevent calling generateFetcherFetch for each query since all the queries won't be able to generate
|
package/index.mjs
CHANGED
|
@@ -13,6 +13,10 @@ function generateInfiniteQueryKey(node, hasRequiredVariables) {
|
|
|
13
13
|
return `['${node.name.value}.infinite', variables]`;
|
|
14
14
|
return `variables === undefined ? ['${node.name.value}.infinite'] : ['${node.name.value}.infinite', variables]`;
|
|
15
15
|
}
|
|
16
|
+
function generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
17
|
+
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
18
|
+
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
19
|
+
}
|
|
16
20
|
function generateQueryKey(node, hasRequiredVariables) {
|
|
17
21
|
if (hasRequiredVariables)
|
|
18
22
|
return `['${node.name.value}', variables]`;
|
|
@@ -23,7 +27,7 @@ function generateQueryKeyMaker(node, operationName, operationVariablesTypes, has
|
|
|
23
27
|
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
24
28
|
}
|
|
25
29
|
function generateMutationKey(node) {
|
|
26
|
-
return `'${node.name.value}'`;
|
|
30
|
+
return `['${node.name.value}']`;
|
|
27
31
|
}
|
|
28
32
|
function generateMutationKeyMaker(node, operationName) {
|
|
29
33
|
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
@@ -59,8 +63,9 @@ class CustomMapperFetcher {
|
|
|
59
63
|
this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
60
64
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
61
65
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
66
|
+
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
62
67
|
const impl = this._isReactHook
|
|
63
|
-
? `(metaData) =>
|
|
68
|
+
? `(metaData) => query({...variables, ...(metaData.pageParam ?? {})})`
|
|
64
69
|
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ?? {})})()`;
|
|
65
70
|
return `export const useInfinite${operationName} = <
|
|
66
71
|
TData = ${operationResultType},
|
|
@@ -68,12 +73,13 @@ class CustomMapperFetcher {
|
|
|
68
73
|
>(
|
|
69
74
|
${variables},
|
|
70
75
|
${options}
|
|
71
|
-
) =>
|
|
72
|
-
${
|
|
76
|
+
) =>{
|
|
77
|
+
${implHookOuter}
|
|
78
|
+
return ${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
73
79
|
${generateInfiniteQueryKey(node, hasRequiredVariables)},
|
|
74
80
|
${impl},
|
|
75
81
|
options
|
|
76
|
-
);`;
|
|
82
|
+
)};`;
|
|
77
83
|
}
|
|
78
84
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
79
85
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
@@ -508,6 +514,9 @@ class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
508
514
|
}
|
|
509
515
|
if (this.config.addInfiniteQuery) {
|
|
510
516
|
query += `\n${this.fetcher.generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables)}\n`;
|
|
517
|
+
if (this.config.exposeQueryKeys) {
|
|
518
|
+
query += `\n${generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables)};\n`;
|
|
519
|
+
}
|
|
511
520
|
}
|
|
512
521
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
513
522
|
// is to prevent calling generateFetcherFetch for each query since all the queries won't be able to generate
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
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
|
-
"@graphql-codegen/plugin-helpers": "2.3.
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.5.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.3.2",
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.5.2",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.14",
|
|
13
13
|
"tslib": "~2.3.0"
|
package/variables-generator.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
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
|
+
export declare function generateInfiniteQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
4
5
|
export declare function generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
5
6
|
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
6
7
|
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|