@graphql-codegen/typescript-react-query 4.0.3-alpha-20221020101303-caea2dc0c → 4.0.3
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/fetcher-custom-mapper.js +4 -2
- package/cjs/fetcher-fetch-hardcoded.js +2 -2
- package/cjs/fetcher-fetch.js +2 -2
- package/cjs/fetcher-graphql-request.js +2 -2
- package/esm/fetcher-custom-mapper.js +4 -2
- package/esm/fetcher-fetch-hardcoded.js +2 -2
- package/esm/fetcher-fetch.js +2 -2
- package/esm/fetcher-graphql-request.js +2 -2
- package/package.json +2 -2
|
@@ -27,6 +27,7 @@ class CustomMapperFetcher {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
30
|
+
const pageParamKey = `pageParamKey: keyof ${operationVariablesTypes}`;
|
|
30
31
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
31
32
|
const hookConfig = this.visitor.queryMethodMap;
|
|
32
33
|
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
@@ -35,12 +36,13 @@ class CustomMapperFetcher {
|
|
|
35
36
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
36
37
|
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
37
38
|
const impl = this._isReactHook
|
|
38
|
-
? `(metaData) => query({...variables,
|
|
39
|
-
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables,
|
|
39
|
+
? `(metaData) => query({...variables, [pageParamKey]: metaData.pageParam })`
|
|
40
|
+
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })()`;
|
|
40
41
|
return `export const useInfinite${operationName} = <
|
|
41
42
|
TData = ${operationResultType},
|
|
42
43
|
TError = ${this.visitor.config.errorType}
|
|
43
44
|
>(
|
|
45
|
+
${pageParamKey},
|
|
44
46
|
${variables},
|
|
45
47
|
${options}
|
|
46
48
|
) =>{
|
|
@@ -55,13 +55,13 @@ ${this.getFetchParams()}
|
|
|
55
55
|
TData = ${operationResultType},
|
|
56
56
|
TError = ${this.visitor.config.errorType}
|
|
57
57
|
>(
|
|
58
|
-
|
|
58
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
59
59
|
${variables},
|
|
60
60
|
${options}
|
|
61
61
|
) =>
|
|
62
62
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
63
63
|
${(0, variables_generator_js_1.generateInfiniteQueryKey)(node, hasRequiredVariables)},
|
|
64
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables,
|
|
64
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
|
|
65
65
|
options
|
|
66
66
|
);`;
|
|
67
67
|
}
|
package/cjs/fetcher-fetch.js
CHANGED
|
@@ -39,13 +39,13 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
39
39
|
TError = ${this.visitor.config.errorType}
|
|
40
40
|
>(
|
|
41
41
|
dataSource: { endpoint: string, fetchParams?: RequestInit },
|
|
42
|
-
|
|
42
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
43
43
|
${variables},
|
|
44
44
|
${options}
|
|
45
45
|
) =>
|
|
46
46
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
47
47
|
${(0, variables_generator_js_1.generateInfiniteQueryKey)(node, hasRequiredVariables)},
|
|
48
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables,
|
|
48
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
|
|
49
49
|
options
|
|
50
50
|
);`;
|
|
51
51
|
}
|
|
@@ -24,7 +24,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
24
24
|
TData = ${operationResultType},
|
|
25
25
|
TError = ${this.visitor.config.errorType}
|
|
26
26
|
>(
|
|
27
|
-
|
|
27
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
28
28
|
client: GraphQLClient,
|
|
29
29
|
${variables},
|
|
30
30
|
${options},
|
|
@@ -32,7 +32,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
32
32
|
) =>
|
|
33
33
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
34
34
|
${(0, variables_generator_js_1.generateInfiniteQueryKey)(node, hasRequiredVariables)},
|
|
35
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables,
|
|
35
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam }, headers)(),
|
|
36
36
|
options
|
|
37
37
|
);`;
|
|
38
38
|
}
|
|
@@ -24,6 +24,7 @@ export class CustomMapperFetcher {
|
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
26
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
27
|
+
const pageParamKey = `pageParamKey: keyof ${operationVariablesTypes}`;
|
|
27
28
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
28
29
|
const hookConfig = this.visitor.queryMethodMap;
|
|
29
30
|
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
@@ -32,12 +33,13 @@ export class CustomMapperFetcher {
|
|
|
32
33
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
33
34
|
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
34
35
|
const impl = this._isReactHook
|
|
35
|
-
? `(metaData) => query({...variables,
|
|
36
|
-
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables,
|
|
36
|
+
? `(metaData) => query({...variables, [pageParamKey]: metaData.pageParam })`
|
|
37
|
+
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })()`;
|
|
37
38
|
return `export const useInfinite${operationName} = <
|
|
38
39
|
TData = ${operationResultType},
|
|
39
40
|
TError = ${this.visitor.config.errorType}
|
|
40
41
|
>(
|
|
42
|
+
${pageParamKey},
|
|
41
43
|
${variables},
|
|
42
44
|
${options}
|
|
43
45
|
) =>{
|
|
@@ -52,13 +52,13 @@ ${this.getFetchParams()}
|
|
|
52
52
|
TData = ${operationResultType},
|
|
53
53
|
TError = ${this.visitor.config.errorType}
|
|
54
54
|
>(
|
|
55
|
-
|
|
55
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
56
56
|
${variables},
|
|
57
57
|
${options}
|
|
58
58
|
) =>
|
|
59
59
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
60
60
|
${generateInfiniteQueryKey(node, hasRequiredVariables)},
|
|
61
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables,
|
|
61
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
|
|
62
62
|
options
|
|
63
63
|
);`;
|
|
64
64
|
}
|
package/esm/fetcher-fetch.js
CHANGED
|
@@ -36,13 +36,13 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
36
36
|
TError = ${this.visitor.config.errorType}
|
|
37
37
|
>(
|
|
38
38
|
dataSource: { endpoint: string, fetchParams?: RequestInit },
|
|
39
|
-
|
|
39
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
40
40
|
${variables},
|
|
41
41
|
${options}
|
|
42
42
|
) =>
|
|
43
43
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
44
44
|
${generateInfiniteQueryKey(node, hasRequiredVariables)},
|
|
45
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables,
|
|
45
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
|
|
46
46
|
options
|
|
47
47
|
);`;
|
|
48
48
|
}
|
|
@@ -21,7 +21,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
21
21
|
TData = ${operationResultType},
|
|
22
22
|
TError = ${this.visitor.config.errorType}
|
|
23
23
|
>(
|
|
24
|
-
|
|
24
|
+
pageParamKey: keyof ${operationVariablesTypes},
|
|
25
25
|
client: GraphQLClient,
|
|
26
26
|
${variables},
|
|
27
27
|
${options},
|
|
@@ -29,7 +29,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
29
29
|
) =>
|
|
30
30
|
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
|
|
31
31
|
${generateInfiniteQueryKey(node, hasRequiredVariables)},
|
|
32
|
-
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables,
|
|
32
|
+
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam }, headers)(),
|
|
33
33
|
options
|
|
34
34
|
);`;
|
|
35
35
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "4.0.3
|
|
3
|
+
"version": "4.0.3",
|
|
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": "^2.6.2",
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.13.0
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.13.0",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.14",
|
|
13
13
|
"tslib": "~2.4.0"
|