@@ -718,6 +718,8 @@ const generateQueryImplementation = ({
718
718
hasQueryV5WithDataTagError,
719
719
doc,
720
720
usePrefetch,
721
+ useQuery,
722
+ useInfinite,
721
723
} : {
722
724
queryOption : {
723
725
name : string ;
@@ -748,6 +750,8 @@ const generateQueryImplementation = ({
748
750
hasQueryV5WithDataTagError : boolean ;
749
751
doc ?: string ;
750
752
usePrefetch ?: boolean ;
753
+ useQuery ?: boolean ;
754
+ useInfinite ?: boolean ;
751
755
} ) => {
752
756
const queryPropDefinitions = toObjectString ( props , 'definition' ) ;
753
757
const definedInitialDataQueryPropsDefinitions = toObjectString (
@@ -1010,6 +1014,20 @@ ${hookOptions}
1010
1014
export function ${ queryHookName } <TData = ${ TData } , TError = ${ errorType } >(\n ${ definedInitialDataQueryPropsDefinitions } ${ definedInitialDataQueryArguments } ${ optionalQueryClientArgument } \n ): ${ definedInitialDataReturnType }
1011
1015
export function ${ queryHookName } <TData = ${ TData } , TError = ${ errorType } >(\n ${ queryPropDefinitions } ${ undefinedInitialDataQueryArguments } ${ optionalQueryClientArgument } \n ): ${ returnType }
1012
1016
export function ${ queryHookName } <TData = ${ TData } , TError = ${ errorType } >(\n ${ queryPropDefinitions } ${ queryArguments } ${ optionalQueryClientArgument } \n ): ${ returnType } ` ;
1017
+
1018
+ const shouldGeneratePrefetch =
1019
+ usePrefetch &&
1020
+ ( type === QueryType . QUERY ||
1021
+ type === QueryType . INFINITE ||
1022
+ ( type === QueryType . SUSPENSE_QUERY && ! useQuery ) ||
1023
+ ( type === QueryType . SUSPENSE_INFINITE && ! useInfinite ) ) ;
1024
+ const prefetchType =
1025
+ type === QueryType . QUERY || type === QueryType . SUSPENSE_QUERY
1026
+ ? 'query'
1027
+ : 'infinite-query' ;
1028
+ const prefetchVarName = camel ( `prefetch-${ operationName } -${ prefetchType } ` ) ;
1029
+ const prefetchFnName = camel ( `prefetch-${ prefetchType } ` ) ;
1030
+
1013
1031
return `
1014
1032
${ queryOptionsFn }
1015
1033
@@ -1037,16 +1055,14 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
1037
1055
return ${ queryResultVarName } ;
1038
1056
}\n
1039
1057
${
1040
- usePrefetch && ( type === QueryType . QUERY || type === QueryType . INFINITE )
1041
- ? `${ doc } export const ${ camel (
1042
- `prefetch-${ name } ` ,
1043
- ) } = async <TData = Awaited<ReturnType<${ dataType } >>, TError = ${ errorType } >(\n queryClient: QueryClient, ${ queryProps } ${ queryArguments } \n ): Promise<QueryClient> => {
1058
+ shouldGeneratePrefetch
1059
+ ? `${ doc } export const ${ prefetchVarName } = async <TData = Awaited<ReturnType<${ dataType } >>, TError = ${ errorType } >(\n queryClient: QueryClient, ${ queryProps } ${ queryArguments } \n ): Promise<QueryClient> => {
1044
1060
1045
1061
const ${ queryOptionsVarName } = ${ queryOptionsFnName } (${ queryProperties } ${
1046
1062
queryProperties ? ',' : ''
1047
1063
} ${ isRequestOptions ? 'options' : 'queryOptions' } )
1048
1064
1049
- await queryClient.${ camel ( `prefetch- ${ type } ` ) } (${ queryOptionsVarName } );
1065
+ await queryClient.${ prefetchFnName } (${ queryOptionsVarName } );
1050
1066
1051
1067
return queryClient;
1052
1068
}\n`
@@ -1282,6 +1298,8 @@ const generateQueryHook = async (
1282
1298
hasQueryV5WithDataTagError,
1283
1299
doc,
1284
1300
usePrefetch : query . usePrefetch ,
1301
+ useQuery : query . useQuery ,
1302
+ useInfinite : query . useInfinite ,
1285
1303
} ) ,
1286
1304
'' ,
1287
1305
) }
0 commit comments