11import {
22 DataTag ,
3+ InfiniteData ,
4+ InfiniteQueryPageParamsOptions ,
35 QueryFilters ,
46 QueryFunction ,
7+ UseInfiniteQueryOptions ,
8+ UseInfiniteQueryResult ,
59 UseQueryOptions ,
10+ UseSuspenseInfiniteQueryResult ,
11+ useInfiniteQuery ,
612 useIsFetching ,
13+ usePrefetchInfiniteQuery ,
714 usePrefetchQuery ,
815 useQueries ,
916 useQuery ,
17+ useSuspenseInfiniteQuery ,
1018 useSuspenseQueries ,
1119 useSuspenseQuery ,
1220} from '@tanstack/react-query' ;
13- import { FunctionType } from '../types/utils' ;
21+ import { FunctionType , TODO } from '../types/utils' ;
1422import { QueryBuilderClient } from './QueryBuilderClient' ;
1523import { BuilderConfig , BuilderQueriesResult } from './types' ;
1624import { mergeQueryOptions , mergeVars } from './utils' ;
1725
26+ export type QueryBuilderOptions < TVars , TData , TError , TKey extends unknown [ ] > = Partial <
27+ UseQueryOptions < TData , TError , TData , TKey > & { queryFn : FunctionType } & InfiniteQueryPageParamsOptions < TData , Partial < TVars > >
28+ > ;
29+
1830export type QueryBuilderConfig < TVars , TData , TError , TKey extends unknown [ ] > = BuilderConfig < TVars , TData , TError , TKey > & {
19- options ?: Partial < UseQueryOptions < TData , TError , TData , TKey > & { queryFn : FunctionType } > ;
31+ options ?: QueryBuilderOptions < TVars , TData , TError , TKey > ;
2032} ;
2133
2234export class QueryBuilderFrozen <
@@ -27,8 +39,7 @@ export class QueryBuilderFrozen<
2739 TTags extends Record < string , unknown > = Record < string , unknown > ,
2840> {
2941 protected declare _config : QueryBuilderConfig < TVars , TData , TError , TKey > ;
30- protected declare _options : typeof this . _config . options ;
31- protected declare _vars : TVars ;
42+ protected declare _options : QueryBuilderOptions < TVars , TData , TError , TKey > ;
3243
3344 constructor ( public config : typeof this . _config ) { }
3445
@@ -50,7 +61,7 @@ export class QueryBuilderFrozen<
5061 return this . config . preprocessorFn ( vars ) ;
5162 } ;
5263
53- getQueryFn : ( ) => QueryFunction < TData , TKey > = ( ) => {
64+ getQueryFn : ( ) => QueryFunction < TData , TKey , Partial < TVars > > = ( ) => {
5465 return ( { client, meta, queryKey, signal, pageParam } ) => {
5566 return this . config . queryFn ( { client, meta, queryKey, signal, pageParam, originalQueryKey : queryKey } ) ;
5667 } ;
@@ -75,6 +86,16 @@ export class QueryBuilderFrozen<
7586 ] ) ;
7687 } ;
7788
89+ getInfiniteQueryOptions : (
90+ vars : TVars ,
91+ opts ?: typeof this . _options ,
92+ ) => UseInfiniteQueryOptions < TData , TError , InfiniteData < TData , Partial < TVars > > , TData , TKey > & { queryFn : FunctionType } = (
93+ vars ,
94+ opts ,
95+ ) => {
96+ return this . getQueryOptions ( vars , opts ) as TODO ;
97+ } ;
98+
7899 useQuery : ( vars : TVars , opts ?: typeof this . _options ) => ReturnType < typeof useQuery < TData , TError , TData , TKey > > = ( vars , opts ) => {
79100 return useQuery ( this . getQueryOptions ( vars , opts ) , this . config . queryClient ) ;
80101 } ;
@@ -135,6 +156,24 @@ export class QueryBuilderFrozen<
135156 return this . useQueriesInternal ( useSuspenseQueries ) ( queries , sharedVars , sharedOpts ) ;
136157 } ;
137158
159+ useInfiniteQuery : ( vars : TVars , opts ?: typeof this . _options ) => UseInfiniteQueryResult < InfiniteData < TData , Partial < TVars > > , TError > = (
160+ vars ,
161+ opts ,
162+ ) => {
163+ return useInfiniteQuery ( this . getInfiniteQueryOptions ( vars , opts ) , this . config . queryClient ) ;
164+ } ;
165+
166+ usePrefetchInfiniteQuery : ( vars : TVars , opts ?: typeof this . _options ) => void = ( vars , opts ) => {
167+ return usePrefetchInfiniteQuery ( this . getInfiniteQueryOptions ( vars , opts ) , this . config . queryClient ) ;
168+ } ;
169+
170+ useSuspenseInfiniteQuery : (
171+ vars : TVars ,
172+ opts ?: typeof this . _options ,
173+ ) => UseSuspenseInfiniteQueryResult < InfiniteData < TData , Partial < TVars > > , TError > = ( vars , opts ) => {
174+ return useSuspenseInfiniteQuery ( this . getInfiniteQueryOptions ( vars , opts ) , this . config . queryClient ) ;
175+ } ;
176+
138177 private _client ?: QueryBuilderClient < TVars , TData , TError , TKey > ;
139178 get client ( ) {
140179 return ( this . _client ??= new QueryBuilderClient ( this ) ) ;
0 commit comments