Skip to content

Commit 0959a10

Browse files
committed
feat(openapi-react-query)!: change queryOptions params
1 parent 5857d4b commit 0959a10

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

.changeset/rich-boxes-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-react-query": minor
3+
---
4+
5+
Removed fourth argument from `queryOptions()`. Use spread operator instead.

docs/openapi-react-query/query-options.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const $api = createClient(fetchClient);
9696
## Api
9797

9898
```tsx
99-
const queryOptions = $api.queryOptions(method, path, options, queryOptions);
99+
const queryOptions = $api.queryOptions(method, path, options);
100100
```
101101

102102
**Arguments**
@@ -112,8 +112,6 @@ const queryOptions = $api.queryOptions(method, path, options, queryOptions);
112112
- The fetch options to use for the request.
113113
- Only required if the OpenApi schema requires parameters.
114114
- The options `params` are used as key. See [Query Keys](https://tanstack.com/query/latest/docs/framework/react/guides/query-keys) for more information.
115-
- `queryOptions`
116-
- Additional query options to pass through.
117115

118116
**Returns**
119117

packages/openapi-react-query/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type QueryKey<
1919
Paths extends Record<string, Record<HttpMethod, {}>>,
2020
Method extends HttpMethod,
2121
Path extends PathsWithMethod<Paths, Method>,
22-
> = readonly [FetchClient<Paths>, Method, Path, MaybeOptionalInit<Paths[Path], Method>];
22+
> = readonly [FetchClient<Paths, MediaType>, Method, Path, MaybeOptionalInit<Paths[Path], Method>];
2323

2424
export type QueryOptionsFunction<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
2525
Method extends HttpMethod,
@@ -33,9 +33,8 @@ export type QueryOptionsFunction<Paths extends Record<string, Record<HttpMethod,
3333
>(
3434
method: Method,
3535
path: Path,
36-
...[init, options]: RequiredKeysOf<Init> extends never
37-
? [InitWithUnknowns<Init>?, Options?]
38-
: [InitWithUnknowns<Init>, Options?]
36+
init?: InitWithUnknowns<Init>,
37+
options?: Options,
3938
) => NoInfer<
4039
Omit<
4140
UseQueryOptions<Response["data"], Response["error"], Response["data"], QueryKey<Paths, Method, Path>>,
@@ -119,18 +118,17 @@ export default function createClient<Paths extends {}, Media extends MediaType =
119118
return data;
120119
};
121120

122-
const queryOptions: QueryOptionsFunction<Paths, Media> = (method, path, ...[init, options]) => ({
121+
const queryOptions: QueryOptionsFunction<Paths, Media> = (method, path, init) => ({
123122
queryKey: [client, method, path, init as InitWithUnknowns<typeof init>] as const,
124123
queryFn,
125-
...options,
126124
});
127125

128126
return {
129127
queryOptions,
130128
useQuery: (method, path, ...[init, options, queryClient]) =>
131-
useQuery(queryOptions(method, path, init as InitWithUnknowns<typeof init>, options), queryClient),
129+
useQuery({ ...queryOptions(method, path, init), ...options }, queryClient),
132130
useSuspenseQuery: (method, path, ...[init, options, queryClient]) =>
133-
useSuspenseQuery(queryOptions(method, path, init as InitWithUnknowns<typeof init>, options), queryClient),
131+
useSuspenseQuery({ ...queryOptions(method, path, init), ...options }, queryClient),
134132
useMutation: (method, path, options, queryClient) =>
135133
useMutation(
136134
{

0 commit comments

Comments
 (0)