Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly committed Nov 7, 2022
1 parent 906e98b commit aee5a7a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/plugins/typescript/react-query/CHANGELOG.md
@@ -1,5 +1,11 @@
# @graphql-codegen/typescript-react-query

## 4.0.5

### Patch Changes

- [#8567](https://github.com/dotansimha/graphql-code-generator/pull/8567) [`af40efbd2`](https://github.com/dotansimha/graphql-code-generator/commit/af40efbd23850c6bdb5f5b3d8713bac24e72fe44) Thanks [@EandrewJones](https://github.com/EandrewJones)! - fixes issue #7549

## 4.0.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/typescript/react-query/package.json
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-react-query",
"version": "4.0.4",
"version": "4.0.5",
"description": "GraphQL Code Generator plugin for generating a ready-to-use React-Query Hooks based on GraphQL operations",
"repository": {
"type": "git",
Expand Down
Expand Up @@ -59,8 +59,8 @@ export class CustomMapperFetcher implements FetcherRenderer {
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
const impl = this._isReactHook
? `(metaData) => query({...variables, [pageParamKey]: metaData.pageParam })`
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })()`;
? `(metaData) => query({...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})`
: `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})()`;

return `export const useInfinite${operationName} = <
TData = ${operationResultType},
Expand Down
Expand Up @@ -83,7 +83,7 @@ ${this.getFetchParams()}
) =>
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
${generateInfiniteQueryKey(node, hasRequiredVariables)},
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
options
);`;
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
) =>
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
${generateInfiniteQueryKey(node, hasRequiredVariables)},
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam })(),
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(dataSource.endpoint, dataSource.fetchParams || {}, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
options
);`;
}
Expand Down
Expand Up @@ -50,7 +50,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
) =>
${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
${generateInfiniteQueryKey(node, hasRequiredVariables)},
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam }, headers)(),
(metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})}, headers)(),
options
);`;
}
Expand Down
Expand Up @@ -40,7 +40,7 @@ export const useInfiniteTestQuery = <
const query = useCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument)
return useInfiniteQuery<TTestQuery, TError, TData>(
variables === undefined ? ['test.infinite'] : ['test.infinite', variables],
(metaData) => query({...variables, [pageParamKey]: metaData.pageParam }),
(metaData) => query({...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})}),
options
)};
Expand Down Expand Up @@ -102,7 +102,7 @@ export const useInfiniteTestQuery = <
return useInfiniteQuery<TTestQuery, TError, TData>(
variables === undefined ? ['test.infinite'] : ['test.infinite', variables],
(metaData) => myCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument, {...variables, [pageParamKey]: metaData.pageParam })(),
(metaData) => myCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
options
)};
Expand Down
Expand Up @@ -93,7 +93,7 @@ export const useInfiniteTestQuery = <
) =>
useInfiniteQuery<TestQuery, TError, TData>(
variables === undefined ? ['test.infinite'] : ['test.infinite', variables],
(metaData) => fetcher<TestQuery, TestQueryVariables>(dataSource.endpoint, dataSource.fetchParams || {}, TestDocument, {...variables, [pageParamKey]: metaData.pageParam })(),
(metaData) => fetcher<TestQuery, TestQueryVariables>(dataSource.endpoint, dataSource.fetchParams || {}, TestDocument, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
options
);
Expand Down Expand Up @@ -269,7 +269,7 @@ export const useTestMutation = <
) =>{
return useInfiniteQuery<TTestQuery, TError, TData>(
variables === undefined ? ['test.infinite'] : ['test.infinite', variables],
(metaData) => myCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument, {...variables, [pageParamKey]: metaData.pageParam })(),
(metaData) => myCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument, {...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})})(),
options
)};`);
expect(out.content).toBeSimilarStringTo(`export const useTestMutation = <
Expand Down Expand Up @@ -366,7 +366,7 @@ export const useTestMutation = <
const query = useCustomFetcher<TTestQuery, TTestQueryVariables>(TestDocument)
return useInfiniteQuery<TTestQuery, TError, TData>(
variables === undefined ? ['test.infinite'] : ['test.infinite', variables],
(metaData) => query({...variables, [pageParamKey]: metaData.pageParam }),
(metaData) => query({...variables, ...(metaData.pageParam ? {[pageParamKey]: metaData.pageParam} : {})}),
options
)};`);
expect(out.content).toBeSimilarStringTo(`export const useTestMutation = <
Expand Down

0 comments on commit aee5a7a

Please sign in to comment.