@graphql-codegen/typescript-react-query 3.3.1 → 3.3.2
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 +7 -0
- package/index.mjs +7 -0
- package/package.json +1 -1
- 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]`;
|
|
@@ -516,6 +520,9 @@ class ReactQueryVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
516
520
|
}
|
|
517
521
|
if (this.config.addInfiniteQuery) {
|
|
518
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
|
+
}
|
|
519
526
|
}
|
|
520
527
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
521
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]`;
|
|
@@ -510,6 +514,9 @@ class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
510
514
|
}
|
|
511
515
|
if (this.config.addInfiniteQuery) {
|
|
512
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
|
+
}
|
|
513
520
|
}
|
|
514
521
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
515
522
|
// 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": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
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"
|
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;
|