Skip to content

Commit 0ee7b4d

Browse files
committed
refactor: remove body from payload key
1 parent 7fdbd57 commit 0ee7b4d

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

packages/react-query/src/index.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,36 @@ export function createKivotosQueryClient<TApiRouter extends ApiRouter<any>>(
7373
restClient: RestClient<TApiRouter>
7474
): KivotosQueryClient<TApiRouter> {
7575
return {
76-
useQuery: function (method: string, path: string, body: any, options?: any) {
76+
useQuery: function (method: string, path: string, payload: any, options?: any) {
7777
return useQuery({
78-
queryKey: queryKey(method, path, body),
78+
queryKey: queryKey(method, path, payload),
7979
queryFn: () => {
80-
return (restClient as any)[method](path, body)
80+
return (restClient as any)[method](path, payload)
8181
},
8282
...options,
8383
}) as UseQueryResult<any, any>
8484
},
85-
useMutation: function (method: string, path: string, body: any, options?: any) {
85+
useMutation: function (method: string, path: string, payload: any, options?: any) {
8686
return useMutation({
87-
mutationKey: queryKey(method, path, body),
87+
mutationKey: queryKey(method, path, payload),
8888
mutationFn: (data) => {
8989
return (restClient as any)[method](path, data)
9090
},
9191
...options,
9292
}) as UseMutationResult<any, any, any, any>
9393
},
94-
queryOptions: function (method: string, path: string, body: any, options?: any) {
94+
queryOptions: function (method: string, path: string, payload: any, options?: any) {
9595
return {
96-
queryKey: queryKey(method, path, body),
96+
queryKey: queryKey(method, path, payload),
9797
queryFn: () => {
98-
return (restClient as any)[method](path, body)
98+
return (restClient as any)[method](path, payload)
9999
},
100100
...options,
101101
} as UseQueryOptions<any, any, any>
102102
},
103-
mutationOptions: function (method: string, path: string, body: any, options?: any) {
103+
mutationOptions: function (method: string, path: string, payload: any, options?: any) {
104104
return {
105-
mutationKey: queryKey(method, path, body),
105+
mutationKey: queryKey(method, path, payload),
106106
mutationFn: (data) => {
107107
return (restClient as any)[method](path, data)
108108
},
@@ -112,6 +112,11 @@ export function createKivotosQueryClient<TApiRouter extends ApiRouter<any>>(
112112
}
113113
}
114114

115-
export function queryKey(method: string, path: string | number | symbol, body: any) {
116-
return [method, path, body] as const
115+
export function queryKey(method: string, path: string | number | symbol, payload: any) {
116+
const payloadKey = {
117+
pathParams: payload?.pathParams ?? {},
118+
query: payload?.query ?? {},
119+
headers: payload?.headers ?? {},
120+
}
121+
return [method, path, payloadKey] as const
117122
}

0 commit comments

Comments
 (0)