@graphql-codegen/typescript-react-query 4.0.4 → 4.0.5-alpha-20221104161441-35b6e33b2

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.
@@ -36,8 +36,8 @@ class CustomMapperFetcher {
36
36
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
37
37
  const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
38
38
  const impl = this._isReactHook
39
- ? `(metaData) => query({...variables, [pageParamKey]: metaData.pageParam })`
40
- : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })()`;
39
+ ? `(metaData) => query({...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})`
40
+ : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})()`;
41
41
  return `export const useInfinite${operationName} = <
42
42
  TData = ${operationResultType},
43
43
  TError = ${this.visitor.config.errorType}
@@ -61,7 +61,7 @@ ${this.getFetchParams()}
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, [pageParamKey]: metaData.pageParam })(),
64
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
65
65
  options
66
66
  );`;
67
67
  }
@@ -45,7 +45,7 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
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, [pageParamKey]: metaData.pageParam })(),
48
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
49
49
  options
50
50
  );`;
51
51
  }
@@ -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, [pageParamKey]: metaData.pageParam }, headers)(),
35
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})}, headers)(),
36
36
  options
37
37
  );`;
38
38
  }
@@ -33,8 +33,8 @@ export class CustomMapperFetcher {
33
33
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
34
34
  const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
35
35
  const impl = this._isReactHook
36
- ? `(metaData) => query({...variables, [pageParamKey]: metaData.pageParam })`
37
- : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })()`;
36
+ ? `(metaData) => query({...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})`
37
+ : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})()`;
38
38
  return `export const useInfinite${operationName} = <
39
39
  TData = ${operationResultType},
40
40
  TError = ${this.visitor.config.errorType}
@@ -58,7 +58,7 @@ ${this.getFetchParams()}
58
58
  ) =>
59
59
  ${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
60
60
  ${generateInfiniteQueryKey(node, hasRequiredVariables)},
61
- (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
61
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
62
62
  options
63
63
  );`;
64
64
  }
@@ -42,7 +42,7 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
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, [pageParamKey]: metaData.pageParam })(),
45
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
46
46
  options
47
47
  );`;
48
48
  }
@@ -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, [pageParamKey]: metaData.pageParam }, headers)(),
32
+ (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})}, headers)(),
33
33
  options
34
34
  );`;
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-react-query",
3
- "version": "4.0.4",
3
+ "version": "4.0.5-alpha-20221104161441-35b6e33b2",
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"