Skip to content

Commit 5fa046e

Browse files
authored
fix(react-query): Override queryKey instead of queryHashKey (#78)
1 parent 8161894 commit 5fa046e

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

.yarn/versions/3bb1dcfd.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@typoas/react-query": patch

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
---
66

7+
## 4.2.2 - 2025-02-12
8+
9+
> Only @typoas/react-query was updated to 4.2.2
10+
11+
- fix(react-query): Override queryKey instead of queryHashKey [#78](https://github.com/Embraser01/typoas/pull/78)
12+
713
## 4.2.1 - 2025-02-12
814

915
> Only @typoas/react-query was updated to 4.2.1

packages/typoas-react-query/src/infinite-query-factory.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
DefaultError,
33
QueryClient,
4-
hashKey,
54
useInfiniteQuery,
65
UseInfiniteQueryOptions,
76
UndefinedInitialDataInfiniteOptions,
@@ -127,15 +126,8 @@ export function createInfiniteQueryHook<
127126
...options,
128127
getNextPageParam,
129128
initialPageParam,
130-
// Override the query key hash function to include the name of the query
131-
// This is the main way to ensure that the query key is unique
132-
// Note that if a user provides a custom queryKeyHashFn,
133-
// they will receive the name as the first argument.
134-
queryKeyHashFn: (queryKey) => {
135-
const hashFn =
136-
options.queryKeyHashFn || baseOptions.queryKeyHashFn || hashKey;
137-
return hashFn([name, ...queryKey]);
138-
},
129+
// Override the query key to differentiate between multiple typoas functions
130+
queryKey: [name, ...options.queryKey],
139131
queryFn: ({ pageParam }) => {
140132
const ctx = localContext || context;
141133
if (!ctx) {

packages/typoas-react-query/src/mutation-factory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@typoas/runtime';
1414
import { useApiContext } from './api-context';
1515
import { TypoasFuncStatusType, TypoasReturnType } from './types';
16+
import { getQueryFunctionKey } from './func-names';
1617

1718
export type TypoasMutationVariables<
1819
Func extends TypoasMutationFunction<FetcherData>,
@@ -94,6 +95,10 @@ export function createMutationHook<
9495
{
9596
...baseOptions,
9697
...options,
98+
// Override the mutation key to differentiate between multiple typoas functions
99+
mutationKey: options.mutationKey
100+
? [getQueryFunctionKey(func), ...options.mutationKey]
101+
: undefined,
97102
mutationFn: ([params, body]) => {
98103
const ctx = localContext || context;
99104
if (!ctx) {

packages/typoas-react-query/src/query-factory.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
useQuery,
66
UseQueryOptions,
77
UseQueryResult,
8-
hashKey,
98
DefaultError,
109
} from '@tanstack/react-query';
1110
import {
@@ -94,15 +93,8 @@ export function createQueryHook<
9493
{
9594
...baseOptions,
9695
...options,
97-
// Override the query key hash function to include the name of the query
98-
// This is the main way to ensure that the query key is unique
99-
// Note that if a user provides a custom queryKeyHashFn,
100-
// they will receive the name as the first argument.
101-
queryKeyHashFn: (queryKey) => {
102-
const hashFn =
103-
options.queryKeyHashFn || baseOptions.queryKeyHashFn || hashKey;
104-
return hashFn([name, ...queryKey]);
105-
},
96+
// Override the query key to differentiate between multiple typoas functions
97+
queryKey: [name, ...options.queryKey],
10698
queryFn: () => {
10799
const ctx = localContext || context;
108100
if (!ctx) {

0 commit comments

Comments
 (0)