Skip to content

Commit 79e9527

Browse files
authoredApr 11, 2023
feat(query): generate query and mutation options functions (#821)
1 parent 6f9ad9c commit 79e9527

File tree

2 files changed

+368
-176
lines changed

2 files changed

+368
-176
lines changed
 

‎packages/query/src/index.ts

+175-97
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,37 @@ const getQueryArgumentsRequestType = (mutator?: GeneratorMutator) => {
457457
return '';
458458
};
459459

460+
const getQueryOptionsDefinition = ({
461+
operationName,
462+
definitions,
463+
mutator,
464+
type,
465+
hasSvelteQueryV4,
466+
}: {
467+
operationName: string;
468+
definitions: string;
469+
mutator?: GeneratorMutator;
470+
type?: QueryType;
471+
hasSvelteQueryV4: boolean;
472+
}) => {
473+
const isMutatorHook = mutator?.isHook;
474+
const prefix = !hasSvelteQueryV4 ? 'Use' : 'Create';
475+
476+
if (type) {
477+
return `${prefix}${pascal(type)}Options<Awaited<ReturnType<${
478+
isMutatorHook
479+
? `ReturnType<typeof use${pascal(operationName)}Hook>`
480+
: `typeof ${operationName}`
481+
}>>, TError, TData>`;
482+
}
483+
484+
return `${prefix}MutationOptions<Awaited<ReturnType<${
485+
isMutatorHook
486+
? `ReturnType<typeof use${pascal(operationName)}Hook>`
487+
: `typeof ${operationName}`
488+
}>>, TError,${definitions ? `{${definitions}}` : 'TVariables'}, TContext>`;
489+
};
490+
460491
const generateQueryArguments = ({
461492
operationName,
462493
definitions,
@@ -472,21 +503,13 @@ const generateQueryArguments = ({
472503
type?: QueryType;
473504
hasSvelteQueryV4: boolean;
474505
}) => {
475-
const isMutatorHook = mutator?.isHook;
476-
const prefix = !hasSvelteQueryV4 ? 'Use' : 'Create';
477-
const definition = type
478-
? `${prefix}${pascal(type)}Options<Awaited<ReturnType<${
479-
isMutatorHook
480-
? `ReturnType<typeof use${pascal(operationName)}Hook>`
481-
: `typeof ${operationName}`
482-
}>>, TError, TData>`
483-
: `${prefix}MutationOptions<Awaited<ReturnType<${
484-
isMutatorHook
485-
? `ReturnType<typeof use${pascal(operationName)}Hook>`
486-
: `typeof ${operationName}`
487-
}>>, TError,${
488-
definitions ? `{${definitions}}` : 'TVariables'
489-
}, TContext>`;
506+
const definition = getQueryOptionsDefinition({
507+
operationName,
508+
definitions,
509+
mutator,
510+
type,
511+
hasSvelteQueryV4,
512+
});
490513

491514
if (!isRequestOptions) {
492515
return `${type ? 'queryOptions' : 'mutationOptions'}?: ${definition}`;
@@ -735,19 +758,30 @@ const generateQueryImplementation = ({
735758
hasSignal,
736759
});
737760

738-
const operationPrefix = hasSvelteQueryV4 ? 'create' : 'use';
761+
const queryOptionFnReturnType = getQueryOptionsDefinition({
762+
operationName,
763+
definitions: '',
764+
mutator,
765+
type,
766+
hasSvelteQueryV4,
767+
});
739768

740-
return `
741-
export type ${pascal(
742-
name,
743-
)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
744-
export type ${pascal(name)}QueryError = ${errorType}
769+
const queryOptionsImp = generateQueryOptions({
770+
params,
771+
options,
772+
type,
773+
});
745774

746-
export const ${camel(
747-
`${operationPrefix}-${name}`,
748-
)} = <TData = Awaited<ReturnType<${dataType}>>, TError = ${errorType}>(\n ${queryProps} ${queryArguments}\n ): ${returnType} => {
775+
const queryOptionsFnName = camel(
776+
queryKeyMutator || queryOptionsMutator || mutator?.isHook
777+
? `use-${name}-queryOptions`
778+
: `get-${name}-queryOptions`,
779+
);
749780

750-
${hookOptions}
781+
const queryOptionsVarName = isRequestOptions ? 'queryOptions' : 'options';
782+
783+
const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = Awaited<ReturnType<${dataType}>>, TError = ${errorType}>(${queryProps} ${queryArguments}): ${queryOptionFnReturnType} & { queryKey: QueryKey } => {
784+
${hookOptions}
751785
752786
const queryKey = ${
753787
!queryKeyMutator
@@ -766,44 +800,56 @@ export const ${camel(
766800
? `const ${operationName} = use${pascal(operationName)}Hook();`
767801
: ''
768802
}
769-
770-
771-
const queryFn: QueryFunction<Awaited<ReturnType<${
772-
mutator?.isHook
773-
? `ReturnType<typeof use${pascal(operationName)}Hook>`
774-
: `typeof ${operationName}`
775-
}>>> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${
803+
804+
const queryFn: QueryFunction<Awaited<ReturnType<${
805+
mutator?.isHook
806+
? `ReturnType<typeof use${pascal(operationName)}Hook>`
807+
: `typeof ${operationName}`
808+
}>>> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${
776809
httpFunctionProps ? ', ' : ''
777810
}${queryOptions});
811+
812+
${
813+
queryOptionsMutator
814+
? `const customOptions = ${
815+
queryOptionsMutator.name
816+
}({...queryOptions, queryKey, queryFn}${
817+
queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ''
818+
}${
819+
queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ''
820+
});`
821+
: ''
822+
}
823+
824+
return ${
825+
!queryOptionsMutator
826+
? `{ queryKey, queryFn, ${queryOptionsImp}}`
827+
: 'customOptions'
828+
}}`;
778829

830+
const operationPrefix = hasSvelteQueryV4 ? 'create' : 'use';
779831

780-
${
781-
queryOptionsMutator
782-
? `const customOptions = ${
783-
queryOptionsMutator.name
784-
}({...queryOptions, queryKey, queryFn}${
785-
queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ''
786-
}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ''});`
787-
: ''
788-
}
832+
return `
833+
${queryOptionsFn}
789834
790-
const query = ${camel(`${operationPrefix}-${type}`)}<Awaited<ReturnType<${
791-
mutator?.isHook
792-
? `ReturnType<typeof use${pascal(operationName)}Hook>`
793-
: `typeof ${operationName}`
794-
}>>, TError, TData>(${
795-
!queryOptionsMutator
796-
? `{ queryKey, queryFn, ${generateQueryOptions({
797-
params,
798-
options,
799-
type,
800-
})}}`
801-
: 'customOptions'
802-
}) as ${returnType};
835+
export type ${pascal(
836+
name,
837+
)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
838+
export type ${pascal(name)}QueryError = ${errorType}
803839
804-
query.queryKey = ${
805-
!queryOptionsMutator ? 'queryKey' : 'customOptions.queryKey'
806-
};
840+
export const ${camel(
841+
`${operationPrefix}-${name}`,
842+
)} = <TData = Awaited<ReturnType<${dataType}>>, TError = ${errorType}>(\n ${queryProps} ${queryArguments}\n ): ${returnType} => {
843+
844+
const ${queryOptionsVarName} = ${queryOptionsFnName}(${queryProperties}${
845+
queryProperties ? ',' : ''
846+
}${isRequestOptions ? 'options' : 'queryOptions'})
847+
848+
const query = ${camel(
849+
`${operationPrefix}-${type}`,
850+
)}(${queryOptionsVarName}) as ${returnType};
851+
852+
query.queryKey = ${queryOptionsVarName}.queryKey;
807853
808854
return query;
809855
}\n`;
@@ -988,45 +1034,45 @@ const generateQueryHook = async (
9881034
? `ReturnType<typeof use${pascal(operationName)}Hook>`
9891035
: `typeof ${operationName}`;
9901036

991-
const operationPrefix = hasSvelteQueryV4 ? 'create' : 'use';
1037+
const mutationOptionFnReturnType = getQueryOptionsDefinition({
1038+
operationName,
1039+
definitions,
1040+
mutator,
1041+
hasSvelteQueryV4,
1042+
});
9921043

993-
const implementation = `
994-
export type ${pascal(
995-
operationName,
996-
)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
997-
${
998-
body.definition
999-
? `export type ${pascal(operationName)}MutationBody = ${
1000-
mutator?.bodyTypeName
1001-
? `${mutator.bodyTypeName}<${body.definition}>`
1002-
: body.definition
1003-
}`
1004-
: ''
1005-
}
1006-
export type ${pascal(operationName)}MutationError = ${errorType}
1044+
const mutationArguments = generateQueryArguments({
1045+
operationName,
1046+
definitions,
1047+
mutator,
1048+
isRequestOptions,
1049+
hasSvelteQueryV4,
1050+
});
10071051

1008-
export const ${camel(
1009-
`${operationPrefix}-${operationName}`,
1010-
)} = <TError = ${errorType},
1052+
const mutationOptionsFnName = camel(
1053+
mutationOptionsMutator || mutator?.isHook
1054+
? `use-${operationName}-mutationOptions`
1055+
: `get-${operationName}-mutationOptions`,
1056+
);
1057+
1058+
const mutationOptionsVarName = isRequestOptions
1059+
? 'mutationOptions'
1060+
: 'options';
1061+
1062+
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
10111063
${!definitions ? `TVariables = void,` : ''}
1012-
TContext = unknown>(${generateQueryArguments({
1013-
operationName,
1014-
definitions,
1015-
mutator,
1016-
isRequestOptions,
1017-
hasSvelteQueryV4,
1018-
})}) => {
1019-
${
1020-
isRequestOptions
1021-
? `const {mutation: mutationOptions${
1022-
!mutator
1023-
? `, axios: axiosOptions`
1024-
: mutator?.hasSecondArg
1025-
? ', request: requestOptions'
1026-
: ''
1027-
}} = options ?? {};`
1028-
: ''
1029-
}
1064+
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
1065+
${
1066+
isRequestOptions
1067+
? `const {mutation: mutationOptions${
1068+
!mutator
1069+
? `, axios: axiosOptions`
1070+
: mutator?.hasSecondArg
1071+
? ', request: requestOptions'
1072+
: ''
1073+
}} = options ?? {};`
1074+
: ''
1075+
}
10301076
10311077
${
10321078
mutator?.isHook
@@ -1063,11 +1109,43 @@ const generateQueryHook = async (
10631109
: ''
10641110
}
10651111
1066-
return ${operationPrefix}Mutation<Awaited<ReturnType<typeof ${operationName}>>, TError, ${
1067-
definitions ? `{${definitions}}` : 'TVariables'
1068-
}, TContext>(${
1069-
!mutationOptionsMutator ? 'mutationFn, mutationOptions' : 'customOptions'
1112+
1113+
return ${
1114+
!mutationOptionsMutator
1115+
? '{ mutationFn, ...mutationOptions }'
1116+
: 'customOptions'
1117+
}}`;
1118+
1119+
const operationPrefix = hasSvelteQueryV4 ? 'create' : 'use';
1120+
1121+
const implementation = `
1122+
${mutationOptionsFn}
1123+
1124+
export type ${pascal(
1125+
operationName,
1126+
)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
1127+
${
1128+
body.definition
1129+
? `export type ${pascal(operationName)}MutationBody = ${
1130+
mutator?.bodyTypeName
1131+
? `${mutator.bodyTypeName}<${body.definition}>`
1132+
: body.definition
1133+
}`
1134+
: ''
1135+
}
1136+
export type ${pascal(operationName)}MutationError = ${errorType}
1137+
1138+
export const ${camel(
1139+
`${operationPrefix}-${operationName}`,
1140+
)} = <TError = ${errorType},
1141+
${!definitions ? `TVariables = void,` : ''}
1142+
TContext = unknown>(${mutationArguments}) => {
1143+
1144+
const ${mutationOptionsVarName} = ${mutationOptionsFnName}(${
1145+
isRequestOptions ? 'options' : 'mutationOptions'
10701146
});
1147+
1148+
return ${operationPrefix}Mutation(${mutationOptionsVarName});
10711149
}
10721150
`;
10731151

‎samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts

+193-79
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ export const listPets = (
4949
export const getListPetsQueryKey = (params?: ListPetsParams, version = 1) =>
5050
[`/v${version}/pets`, ...(params ? [params] : [])] as const;
5151

52+
export const getListPetsInfiniteQueryOptions = <
53+
TData = Awaited<ReturnType<typeof listPets>>,
54+
TError = ErrorType<Error>,
55+
>(
56+
params?: ListPetsParams,
57+
version = 1,
58+
options?: {
59+
query?: UseInfiniteQueryOptions<
60+
Awaited<ReturnType<typeof listPets>>,
61+
TError,
62+
TData
63+
>;
64+
},
65+
): UseInfiniteQueryOptions<
66+
Awaited<ReturnType<typeof listPets>>,
67+
TError,
68+
TData
69+
> & { queryKey: QueryKey } => {
70+
const { query: queryOptions } = options ?? {};
71+
72+
const queryKey =
73+
queryOptions?.queryKey ?? getListPetsQueryKey(params, version);
74+
75+
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPets>>> = ({
76+
signal,
77+
pageParam,
78+
}) => listPets({ limit: pageParam, ...params }, version, signal);
79+
80+
return { queryKey, queryFn, enabled: !!version, ...queryOptions };
81+
};
82+
5283
export type ListPetsInfiniteQueryResult = NonNullable<
5384
Awaited<ReturnType<typeof listPets>>
5485
>;
@@ -68,30 +99,49 @@ export const useListPetsInfinite = <
6899
>;
69100
},
70101
): UseInfiniteQueryResult<TData, TError> & { queryKey: QueryKey } => {
102+
const listPetsInfiniteQueryOptions = getListPetsInfiniteQueryOptions(
103+
params,
104+
version,
105+
options,
106+
);
107+
108+
const query = useInfiniteQuery(
109+
listPetsInfiniteQueryOptions,
110+
) as UseInfiniteQueryResult<TData, TError> & {
111+
queryKey: QueryKey;
112+
};
113+
114+
query.queryKey = listPetsInfiniteQueryOptions.queryKey;
115+
116+
return query;
117+
};
118+
119+
export const getListPetsQueryOptions = <
120+
TData = Awaited<ReturnType<typeof listPets>>,
121+
TError = ErrorType<Error>,
122+
>(
123+
params?: ListPetsParams,
124+
version = 1,
125+
options?: {
126+
query?: UseQueryOptions<
127+
Awaited<ReturnType<typeof listPets>>,
128+
TError,
129+
TData
130+
>;
131+
},
132+
): UseQueryOptions<Awaited<ReturnType<typeof listPets>>, TError, TData> & {
133+
queryKey: QueryKey;
134+
} => {
71135
const { query: queryOptions } = options ?? {};
72136

73137
const queryKey =
74138
queryOptions?.queryKey ?? getListPetsQueryKey(params, version);
75139

76140
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPets>>> = ({
77141
signal,
78-
pageParam,
79-
}) => listPets({ limit: pageParam, ...params }, version, signal);
80-
81-
const query = useInfiniteQuery<
82-
Awaited<ReturnType<typeof listPets>>,
83-
TError,
84-
TData
85-
>({
86-
queryKey,
87-
queryFn,
88-
enabled: !!version,
89-
...queryOptions,
90-
}) as UseInfiniteQueryResult<TData, TError> & { queryKey: QueryKey };
91-
92-
query.queryKey = queryKey;
142+
}) => listPets(params, version, signal);
93143

94-
return query;
144+
return { queryKey, queryFn, enabled: !!version, ...queryOptions };
95145
};
96146

97147
export type ListPetsQueryResult = NonNullable<
@@ -113,23 +163,18 @@ export const useListPets = <
113163
>;
114164
},
115165
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
116-
const { query: queryOptions } = options ?? {};
117-
118-
const queryKey =
119-
queryOptions?.queryKey ?? getListPetsQueryKey(params, version);
120-
121-
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPets>>> = ({
122-
signal,
123-
}) => listPets(params, version, signal);
166+
const listPetsQueryOptions = getListPetsQueryOptions(
167+
params,
168+
version,
169+
options,
170+
);
124171

125-
const query = useQuery<Awaited<ReturnType<typeof listPets>>, TError, TData>({
126-
queryKey,
127-
queryFn,
128-
enabled: !!version,
129-
...queryOptions,
130-
}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
172+
const query = useQuery(listPetsQueryOptions) as UseQueryResult<
173+
TData,
174+
TError
175+
> & { queryKey: QueryKey };
131176

132-
query.queryKey = queryKey;
177+
query.queryKey = listPetsQueryOptions.queryKey;
133178

134179
return query;
135180
};
@@ -146,40 +191,68 @@ export const createPets = (createPetsBody: CreatePetsBody, version = 1) => {
146191
});
147192
};
148193

149-
export type CreatePetsMutationResult = NonNullable<
150-
Awaited<ReturnType<typeof createPets>>
151-
>;
152-
export type CreatePetsMutationBody = CreatePetsBody;
153-
export type CreatePetsMutationError = ErrorType<Error>;
154-
155-
export const useCreatePets = <
194+
export const getCreatePetsMutationOptions = <
156195
TError = ErrorType<Error>,
157196
TContext = unknown,
158197
>(options?: {
159198
mutation?: UseMutationOptions<
160199
Awaited<ReturnType<typeof createPets>>,
161200
TError,
162-
{ data: CreatePetsBody; version?: number },
201+
{
202+
data: CreatePetsBody;
203+
version?: number;
204+
},
163205
TContext
164206
>;
165-
}) => {
207+
}): UseMutationOptions<
208+
Awaited<ReturnType<typeof createPets>>,
209+
TError,
210+
{
211+
data: CreatePetsBody;
212+
version?: number;
213+
},
214+
TContext
215+
> => {
166216
const { mutation: mutationOptions } = options ?? {};
167217

168218
const mutationFn: MutationFunction<
169219
Awaited<ReturnType<typeof createPets>>,
170-
{ data: CreatePetsBody; version?: number }
220+
{
221+
data: CreatePetsBody;
222+
version?: number;
223+
}
171224
> = (props) => {
172225
const { data, version } = props ?? {};
173226

174227
return createPets(data, version);
175228
};
176229

177-
return useMutation<
230+
return { mutationFn, ...mutationOptions };
231+
};
232+
233+
export type CreatePetsMutationResult = NonNullable<
234+
Awaited<ReturnType<typeof createPets>>
235+
>;
236+
export type CreatePetsMutationBody = CreatePetsBody;
237+
export type CreatePetsMutationError = ErrorType<Error>;
238+
239+
export const useCreatePets = <
240+
TError = ErrorType<Error>,
241+
TContext = unknown,
242+
>(options?: {
243+
mutation?: UseMutationOptions<
178244
Awaited<ReturnType<typeof createPets>>,
179245
TError,
180-
{ data: CreatePetsBody; version?: number },
246+
{
247+
data: CreatePetsBody;
248+
version?: number;
249+
},
181250
TContext
182-
>(mutationFn, mutationOptions);
251+
>;
252+
}) => {
253+
const createPetsMutationOptions = getCreatePetsMutationOptions(options);
254+
255+
return useMutation(createPetsMutationOptions);
183256
};
184257

185258
/**
@@ -248,6 +321,36 @@ export const showPetById = (
248321
export const getShowPetByIdQueryKey = (petId: string, version = 1) =>
249322
[`/v${version}/pets/${petId}`] as const;
250323

324+
export const getShowPetByIdInfiniteQueryOptions = <
325+
TData = Awaited<ReturnType<typeof showPetById>>,
326+
TError = ErrorType<Error>,
327+
>(
328+
petId: string,
329+
version = 1,
330+
options?: {
331+
query?: UseInfiniteQueryOptions<
332+
Awaited<ReturnType<typeof showPetById>>,
333+
TError,
334+
TData
335+
>;
336+
},
337+
): UseInfiniteQueryOptions<
338+
Awaited<ReturnType<typeof showPetById>>,
339+
TError,
340+
TData
341+
> & { queryKey: QueryKey } => {
342+
const { query: queryOptions } = options ?? {};
343+
344+
const queryKey =
345+
queryOptions?.queryKey ?? getShowPetByIdQueryKey(petId, version);
346+
347+
const queryFn: QueryFunction<Awaited<ReturnType<typeof showPetById>>> = ({
348+
signal,
349+
}) => showPetById(petId, version, signal);
350+
351+
return { queryKey, queryFn, enabled: !!(version && petId), ...queryOptions };
352+
};
353+
251354
export type ShowPetByIdInfiniteQueryResult = NonNullable<
252355
Awaited<ReturnType<typeof showPetById>>
253356
>;
@@ -267,6 +370,39 @@ export const useShowPetByIdInfinite = <
267370
>;
268371
},
269372
): UseInfiniteQueryResult<TData, TError> & { queryKey: QueryKey } => {
373+
const showPetByIdInfiniteQueryOptions = getShowPetByIdInfiniteQueryOptions(
374+
petId,
375+
version,
376+
options,
377+
);
378+
379+
const query = useInfiniteQuery(
380+
showPetByIdInfiniteQueryOptions,
381+
) as UseInfiniteQueryResult<TData, TError> & {
382+
queryKey: QueryKey;
383+
};
384+
385+
query.queryKey = showPetByIdInfiniteQueryOptions.queryKey;
386+
387+
return query;
388+
};
389+
390+
export const getShowPetByIdQueryOptions = <
391+
TData = Awaited<ReturnType<typeof showPetById>>,
392+
TError = ErrorType<Error>,
393+
>(
394+
petId: string,
395+
version = 1,
396+
options?: {
397+
query?: UseQueryOptions<
398+
Awaited<ReturnType<typeof showPetById>>,
399+
TError,
400+
TData
401+
>;
402+
},
403+
): UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData> & {
404+
queryKey: QueryKey;
405+
} => {
270406
const { query: queryOptions } = options ?? {};
271407

272408
const queryKey =
@@ -276,20 +412,7 @@ export const useShowPetByIdInfinite = <
276412
signal,
277413
}) => showPetById(petId, version, signal);
278414

279-
const query = useInfiniteQuery<
280-
Awaited<ReturnType<typeof showPetById>>,
281-
TError,
282-
TData
283-
>({
284-
queryKey,
285-
queryFn,
286-
enabled: !!(version && petId),
287-
...queryOptions,
288-
}) as UseInfiniteQueryResult<TData, TError> & { queryKey: QueryKey };
289-
290-
query.queryKey = queryKey;
291-
292-
return query;
415+
return { queryKey, queryFn, enabled: !!(version && petId), ...queryOptions };
293416
};
294417

295418
export type ShowPetByIdQueryResult = NonNullable<
@@ -311,27 +434,18 @@ export const useShowPetById = <
311434
>;
312435
},
313436
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
314-
const { query: queryOptions } = options ?? {};
315-
316-
const queryKey =
317-
queryOptions?.queryKey ?? getShowPetByIdQueryKey(petId, version);
318-
319-
const queryFn: QueryFunction<Awaited<ReturnType<typeof showPetById>>> = ({
320-
signal,
321-
}) => showPetById(petId, version, signal);
322-
323-
const query = useQuery<
324-
Awaited<ReturnType<typeof showPetById>>,
325-
TError,
326-
TData
327-
>({
328-
queryKey,
329-
queryFn,
330-
enabled: !!(version && petId),
331-
...queryOptions,
332-
}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
333-
334-
query.queryKey = queryKey;
437+
const showPetByIdQueryOptions = getShowPetByIdQueryOptions(
438+
petId,
439+
version,
440+
options,
441+
);
442+
443+
const query = useQuery(showPetByIdQueryOptions) as UseQueryResult<
444+
TData,
445+
TError
446+
> & { queryKey: QueryKey };
447+
448+
query.queryKey = showPetByIdQueryOptions.queryKey;
335449

336450
return query;
337451
};

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 11, 2023

@vercel[bot]
Please sign in to comment.