Skip to content

Commit 67d1918

Browse files
committed
feat(@tanstack/query)!: enable useQuery by default with queryOptions override
1 parent 25d56de commit 67d1918

92 files changed

Lines changed: 15598 additions & 88 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@hey-api/openapi-ts": minor
3+
---
4+
5+
**plugin(@tanstack/react-query, @tanstack/preact-query)**: feat: enable `useQuery` hook generation by default and add `queryOptions` override parameter
6+
7+
`useQuery` hook generation now defaults to `true` for React Query and Preact Query plugins. Generated hooks accept an optional `queryOptions` property (typed as `Partial<Omit<ReturnType<typeof xOptions>, 'queryKey' | 'queryFn'>>`) that is spread over the computed query options, mirroring the existing `mutationOptions` override on `useMutation` hooks.
8+
9+
Opt out of `useQuery` hook generation with `useQuery: false`.

packages/openapi-ts-tests/tanstack-query/v5/__snapshots__/2.0.x/plugins/asClass/@tanstack/preact-query.gen.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanstack/preact-query';
3+
import { type DefaultError, queryOptions, type UseMutationOptions, useQuery } from '@tanstack/preact-query';
44

55
import { client } from '../client.gen';
66
import { BarBazService, BarService, FooBazService, FooService, type Options } from '../sdk.gen';
@@ -54,6 +54,13 @@ export const getFooOptions = (options?: Options<GetFooData>) => queryOptions<Get
5454
queryKey: getFooQueryKey(options)
5555
});
5656

57+
export const useGetFooQuery = (options?: Options<GetFooData> & {
58+
queryOptions?: Partial<Omit<ReturnType<typeof getFooOptions>, 'queryKey' | 'queryFn'>>;
59+
}) => {
60+
const { queryOptions, ...sdkOptions } = options ?? {};
61+
return useQuery({ ...getFooOptions(sdkOptions), ...queryOptions });
62+
};
63+
5764
export const fooPostMutation = (options?: Partial<Options<FooPostData>>): UseMutationOptions<FooPostResponse, DefaultError, Options<FooPostData>> => {
5865
const mutationOptions: UseMutationOptions<FooPostResponse, DefaultError, Options<FooPostData>> = {
5966
mutationFn: async (fnOptions) => {
@@ -97,6 +104,13 @@ export const getFooBarOptions = (options?: Options<GetFooBarData>) => queryOptio
97104
queryKey: getFooBarQueryKey(options)
98105
});
99106

107+
export const useGetFooBarQuery = (options?: Options<GetFooBarData> & {
108+
queryOptions?: Partial<Omit<ReturnType<typeof getFooBarOptions>, 'queryKey' | 'queryFn'>>;
109+
}) => {
110+
const { queryOptions, ...sdkOptions } = options ?? {};
111+
return useQuery({ ...getFooBarOptions(sdkOptions), ...queryOptions });
112+
};
113+
100114
export const fooBarPostMutation = (options?: Partial<Options<FooBarPostData>>): UseMutationOptions<FooBarPostResponse, DefaultError, Options<FooBarPostData>> => {
101115
const mutationOptions: UseMutationOptions<FooBarPostResponse, DefaultError, Options<FooBarPostData>> = {
102116
mutationFn: async (fnOptions) => {

packages/openapi-ts-tests/tanstack-query/v5/__snapshots__/2.0.x/plugins/asClass/@tanstack/react-query.gen.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanstack/react-query';
3+
import { type DefaultError, queryOptions, type UseMutationOptions, useQuery } from '@tanstack/react-query';
44

55
import { client } from '../client.gen';
66
import { BarBazService, BarService, FooBazService, FooService, type Options } from '../sdk.gen';
@@ -54,6 +54,13 @@ export const getFooOptions = (options?: Options<GetFooData>) => queryOptions<Get
5454
queryKey: getFooQueryKey(options)
5555
});
5656

57+
export const useGetFooQuery = (options?: Options<GetFooData> & {
58+
queryOptions?: Partial<Omit<ReturnType<typeof getFooOptions>, 'queryKey' | 'queryFn'>>;
59+
}) => {
60+
const { queryOptions, ...sdkOptions } = options ?? {};
61+
return useQuery({ ...getFooOptions(sdkOptions), ...queryOptions });
62+
};
63+
5764
export const fooPostMutation = (options?: Partial<Options<FooPostData>>): UseMutationOptions<FooPostResponse, DefaultError, Options<FooPostData>> => {
5865
const mutationOptions: UseMutationOptions<FooPostResponse, DefaultError, Options<FooPostData>> = {
5966
mutationFn: async (fnOptions) => {
@@ -97,6 +104,13 @@ export const getFooBarOptions = (options?: Options<GetFooBarData>) => queryOptio
97104
queryKey: getFooBarQueryKey(options)
98105
});
99106

107+
export const useGetFooBarQuery = (options?: Options<GetFooBarData> & {
108+
queryOptions?: Partial<Omit<ReturnType<typeof getFooBarOptions>, 'queryKey' | 'queryFn'>>;
109+
}) => {
110+
const { queryOptions, ...sdkOptions } = options ?? {};
111+
return useQuery({ ...getFooBarOptions(sdkOptions), ...queryOptions });
112+
};
113+
100114
export const fooBarPostMutation = (options?: Partial<Options<FooBarPostData>>): UseMutationOptions<FooBarPostResponse, DefaultError, Options<FooBarPostData>> => {
101115
const mutationOptions: UseMutationOptions<FooBarPostResponse, DefaultError, Options<FooBarPostData>> = {
102116
mutationFn: async (fnOptions) => {

packages/openapi-ts-tests/tanstack-query/v5/__snapshots__/2.0.x/plugins/axios/@tanstack/preact-query.gen.ts

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanstack/preact-query';
3+
import { type DefaultError, queryOptions, type UseMutationOptions, useQuery } from '@tanstack/preact-query';
44
import type { AxiosError } from 'axios';
55

66
import { client } from '../client.gen';
@@ -55,6 +55,13 @@ export const serviceWithEmptyTagOptions = (options?: Options<ServiceWithEmptyTag
5555
queryKey: serviceWithEmptyTagQueryKey(options)
5656
});
5757

58+
export const useServiceWithEmptyTagQuery = (options?: Options<ServiceWithEmptyTagData> & {
59+
queryOptions?: Partial<Omit<ReturnType<typeof serviceWithEmptyTagOptions>, 'queryKey' | 'queryFn'>>;
60+
}) => {
61+
const { queryOptions, ...sdkOptions } = options ?? {};
62+
return useQuery({ ...serviceWithEmptyTagOptions(sdkOptions), ...queryOptions });
63+
};
64+
5865
export const patchApiVbyApiVersionNoTagMutation = (options?: Partial<Options<PatchApiVbyApiVersionNoTagData>>): UseMutationOptions<unknown, AxiosError<DefaultError>, Options<PatchApiVbyApiVersionNoTagData>> => {
5966
const mutationOptions: UseMutationOptions<unknown, AxiosError<DefaultError>, Options<PatchApiVbyApiVersionNoTagData>> = {
6067
mutationFn: async (fnOptions) => {
@@ -112,6 +119,13 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options<Get
112119
queryKey: getCallWithoutParametersAndResponseQueryKey(options)
113120
});
114121

122+
export const useGetCallWithoutParametersAndResponseQuery = (options?: Options<GetCallWithoutParametersAndResponseData> & {
123+
queryOptions?: Partial<Omit<ReturnType<typeof getCallWithoutParametersAndResponseOptions>, 'queryKey' | 'queryFn'>>;
124+
}) => {
125+
const { queryOptions, ...sdkOptions } = options ?? {};
126+
return useQuery({ ...getCallWithoutParametersAndResponseOptions(sdkOptions), ...queryOptions });
127+
};
128+
115129
export const patchCallWithoutParametersAndResponseMutation = (options?: Partial<Options<PatchCallWithoutParametersAndResponseData>>): UseMutationOptions<unknown, AxiosError<DefaultError>, Options<PatchCallWithoutParametersAndResponseData>> => {
116130
const mutationOptions: UseMutationOptions<unknown, AxiosError<DefaultError>, Options<PatchCallWithoutParametersAndResponseData>> = {
117131
mutationFn: async (fnOptions) => {
@@ -211,6 +225,13 @@ export const callWithDefaultParametersOptions = (options: Options<CallWithDefaul
211225
queryKey: callWithDefaultParametersQueryKey(options)
212226
});
213227

228+
export const useCallWithDefaultParametersQuery = (options: Options<CallWithDefaultParametersData> & {
229+
queryOptions?: Partial<Omit<ReturnType<typeof callWithDefaultParametersOptions>, 'queryKey' | 'queryFn'>>;
230+
}) => {
231+
const { queryOptions, ...sdkOptions } = options;
232+
return useQuery({ ...callWithDefaultParametersOptions(sdkOptions), ...queryOptions });
233+
};
234+
214235
export const callWithDefaultOptionalParametersMutation = (options?: Partial<Options<CallWithDefaultOptionalParametersData>>): UseMutationOptions<unknown, AxiosError<DefaultError>, Options<CallWithDefaultOptionalParametersData>> => {
215236
const mutationOptions: UseMutationOptions<unknown, AxiosError<DefaultError>, Options<CallWithDefaultOptionalParametersData>> = {
216237
mutationFn: async (fnOptions) => {
@@ -268,6 +289,13 @@ export const duplicateName2Options = (options?: Options<DuplicateName2Data>) =>
268289
queryKey: duplicateName2QueryKey(options)
269290
});
270291

292+
export const useDuplicateName2Query = (options?: Options<DuplicateName2Data> & {
293+
queryOptions?: Partial<Omit<ReturnType<typeof duplicateName2Options>, 'queryKey' | 'queryFn'>>;
294+
}) => {
295+
const { queryOptions, ...sdkOptions } = options ?? {};
296+
return useQuery({ ...duplicateName2Options(sdkOptions), ...queryOptions });
297+
};
298+
271299
export const duplicateName3Mutation = (options?: Partial<Options<DuplicateName3Data>>): UseMutationOptions<unknown, AxiosError<DefaultError>, Options<DuplicateName3Data>> => {
272300
const mutationOptions: UseMutationOptions<unknown, AxiosError<DefaultError>, Options<DuplicateName3Data>> = {
273301
mutationFn: async (fnOptions) => {
@@ -311,6 +339,13 @@ export const callWithNoContentResponseOptions = (options?: Options<CallWithNoCon
311339
queryKey: callWithNoContentResponseQueryKey(options)
312340
});
313341

342+
export const useCallWithNoContentResponseQuery = (options?: Options<CallWithNoContentResponseData> & {
343+
queryOptions?: Partial<Omit<ReturnType<typeof callWithNoContentResponseOptions>, 'queryKey' | 'queryFn'>>;
344+
}) => {
345+
const { queryOptions, ...sdkOptions } = options ?? {};
346+
return useQuery({ ...callWithNoContentResponseOptions(sdkOptions), ...queryOptions });
347+
};
348+
314349
export const callWithResponseAndNoContentResponseQueryKey = (options?: Options<CallWithResponseAndNoContentResponseData>) => createQueryKey('callWithResponseAndNoContentResponse', options);
315350

316351
export const callWithResponseAndNoContentResponseOptions = (options?: Options<CallWithResponseAndNoContentResponseData>) => queryOptions<CallWithResponseAndNoContentResponseResponse, AxiosError<DefaultError>, CallWithResponseAndNoContentResponseResponse, ReturnType<typeof callWithResponseAndNoContentResponseQueryKey>>({
@@ -326,6 +361,13 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options<Ca
326361
queryKey: callWithResponseAndNoContentResponseQueryKey(options)
327362
});
328363

364+
export const useCallWithResponseAndNoContentResponseQuery = (options?: Options<CallWithResponseAndNoContentResponseData> & {
365+
queryOptions?: Partial<Omit<ReturnType<typeof callWithResponseAndNoContentResponseOptions>, 'queryKey' | 'queryFn'>>;
366+
}) => {
367+
const { queryOptions, ...sdkOptions } = options ?? {};
368+
return useQuery({ ...callWithResponseAndNoContentResponseOptions(sdkOptions), ...queryOptions });
369+
};
370+
329371
export const dummyAQueryKey = (options?: Options<DummyAData>) => createQueryKey('dummyA', options);
330372

331373
export const dummyAOptions = (options?: Options<DummyAData>) => queryOptions<unknown, AxiosError<DefaultError>, unknown, ReturnType<typeof dummyAQueryKey>>({
@@ -341,6 +383,13 @@ export const dummyAOptions = (options?: Options<DummyAData>) => queryOptions<unk
341383
queryKey: dummyAQueryKey(options)
342384
});
343385

386+
export const useDummyAQuery = (options?: Options<DummyAData> & {
387+
queryOptions?: Partial<Omit<ReturnType<typeof dummyAOptions>, 'queryKey' | 'queryFn'>>;
388+
}) => {
389+
const { queryOptions, ...sdkOptions } = options ?? {};
390+
return useQuery({ ...dummyAOptions(sdkOptions), ...queryOptions });
391+
};
392+
344393
export const dummyBQueryKey = (options?: Options<DummyBData>) => createQueryKey('dummyB', options);
345394

346395
export const dummyBOptions = (options?: Options<DummyBData>) => queryOptions<unknown, AxiosError<DefaultError>, unknown, ReturnType<typeof dummyBQueryKey>>({
@@ -356,6 +405,13 @@ export const dummyBOptions = (options?: Options<DummyBData>) => queryOptions<unk
356405
queryKey: dummyBQueryKey(options)
357406
});
358407

408+
export const useDummyBQuery = (options?: Options<DummyBData> & {
409+
queryOptions?: Partial<Omit<ReturnType<typeof dummyBOptions>, 'queryKey' | 'queryFn'>>;
410+
}) => {
411+
const { queryOptions, ...sdkOptions } = options ?? {};
412+
return useQuery({ ...dummyBOptions(sdkOptions), ...queryOptions });
413+
};
414+
359415
export const callWithResponseQueryKey = (options?: Options<CallWithResponseData>) => createQueryKey('callWithResponse', options);
360416

361417
export const callWithResponseOptions = (options?: Options<CallWithResponseData>) => queryOptions<CallWithResponseResponse, AxiosError<DefaultError>, CallWithResponseResponse, ReturnType<typeof callWithResponseQueryKey>>({
@@ -371,6 +427,13 @@ export const callWithResponseOptions = (options?: Options<CallWithResponseData>)
371427
queryKey: callWithResponseQueryKey(options)
372428
});
373429

430+
export const useCallWithResponseQuery = (options?: Options<CallWithResponseData> & {
431+
queryOptions?: Partial<Omit<ReturnType<typeof callWithResponseOptions>, 'queryKey' | 'queryFn'>>;
432+
}) => {
433+
const { queryOptions, ...sdkOptions } = options ?? {};
434+
return useQuery({ ...callWithResponseOptions(sdkOptions), ...queryOptions });
435+
};
436+
374437
export const callWithDuplicateResponsesMutation = (options?: Partial<Options<CallWithDuplicateResponsesData>>): UseMutationOptions<CallWithDuplicateResponsesResponse, AxiosError<CallWithDuplicateResponsesError>, Options<CallWithDuplicateResponsesData>> => {
375438
const mutationOptions: UseMutationOptions<CallWithDuplicateResponsesResponse, AxiosError<CallWithDuplicateResponsesError>, Options<CallWithDuplicateResponsesData>> = {
376439
mutationFn: async (fnOptions) => {
@@ -414,6 +477,13 @@ export const collectionFormatOptions = (options: Options<CollectionFormatData>)
414477
queryKey: collectionFormatQueryKey(options)
415478
});
416479

480+
export const useCollectionFormatQuery = (options: Options<CollectionFormatData> & {
481+
queryOptions?: Partial<Omit<ReturnType<typeof collectionFormatOptions>, 'queryKey' | 'queryFn'>>;
482+
}) => {
483+
const { queryOptions, ...sdkOptions } = options;
484+
return useQuery({ ...collectionFormatOptions(sdkOptions), ...queryOptions });
485+
};
486+
417487
export const typesQueryKey = (options: Options<TypesData>) => createQueryKey('types', options);
418488

419489
export const typesOptions = (options: Options<TypesData>) => queryOptions<TypesResponse, AxiosError<DefaultError>, TypesResponse, ReturnType<typeof typesQueryKey>>({
@@ -429,6 +499,13 @@ export const typesOptions = (options: Options<TypesData>) => queryOptions<TypesR
429499
queryKey: typesQueryKey(options)
430500
});
431501

502+
export const useTypesQuery = (options: Options<TypesData> & {
503+
queryOptions?: Partial<Omit<ReturnType<typeof typesOptions>, 'queryKey' | 'queryFn'>>;
504+
}) => {
505+
const { queryOptions, ...sdkOptions } = options;
506+
return useQuery({ ...typesOptions(sdkOptions), ...queryOptions });
507+
};
508+
432509
export const complexTypesQueryKey = (options: Options<ComplexTypesData>) => createQueryKey('complexTypes', options);
433510

434511
export const complexTypesOptions = (options: Options<ComplexTypesData>) => queryOptions<ComplexTypesResponse, AxiosError<DefaultError>, ComplexTypesResponse, ReturnType<typeof complexTypesQueryKey>>({
@@ -444,6 +521,13 @@ export const complexTypesOptions = (options: Options<ComplexTypesData>) => query
444521
queryKey: complexTypesQueryKey(options)
445522
});
446523

524+
export const useComplexTypesQuery = (options: Options<ComplexTypesData> & {
525+
queryOptions?: Partial<Omit<ReturnType<typeof complexTypesOptions>, 'queryKey' | 'queryFn'>>;
526+
}) => {
527+
const { queryOptions, ...sdkOptions } = options;
528+
return useQuery({ ...complexTypesOptions(sdkOptions), ...queryOptions });
529+
};
530+
447531
export const callWithResultFromHeaderMutation = (options?: Partial<Options<CallWithResultFromHeaderData>>): UseMutationOptions<unknown, AxiosError<DefaultError>, Options<CallWithResultFromHeaderData>> => {
448532
const mutationOptions: UseMutationOptions<unknown, AxiosError<DefaultError>, Options<CallWithResultFromHeaderData>> = {
449533
mutationFn: async (fnOptions) => {

0 commit comments

Comments
 (0)