@@ -19,6 +19,11 @@ export class QueryBuilder<
1919 TTags extends Record < string , unknown > ,
2020 TFlags extends BuilderFlags = '' ,
2121> extends QueryBuilderFrozen < TVars , TData , TError , TKey , TTags , TFlags > {
22+ /**
23+ * Declares the type of variables of the query.
24+ * Optionally, you can pass the first argument to set the default variables,
25+ * which will be merged with the variables passed to the query.
26+ */
2227 withVars < TVars$ = TVars , const TReset extends boolean = false > (
2328 vars ?: TVars$ ,
2429 resetVars = false as TReset ,
@@ -30,21 +35,39 @@ export class QueryBuilder<
3035 } ) as any ;
3136 }
3237
38+ /**
39+ * Declares the type of returned data of the query.
40+ */
3341 withData < TData$ > ( ) : QueryBuilder < TVars , TData$ , TError , TKey , TTags , TFlags > {
3442 return this as any ;
3543 }
3644
45+ /**
46+ * Declares the type of error of the query.
47+ */
3748 withError < TError$ > ( ) : QueryBuilder < TVars , TData , TError$ , TKey , TTags , TFlags > {
3849 return this as any ;
3950 }
4051
52+ /**
53+ * Creates a new query builder with additional config.
54+ */
4155 withConfig ( config : Partial < typeof this . config > ) : this {
4256 const ctor = this . constructor as typeof QueryBuilder ;
4357 const newConfig = this . mergeConfigs ( this . config , config ) ;
4458 return new ctor ( newConfig ) as this;
4559 }
4660
61+ /**
62+ * Adds a preprocessor function to the query.
63+ * The preprocessor function is called before the query function is called.
64+ */
4765 withPreprocessor ( preprocessor : PreprocessorFn < TVars , TVars > ) : this;
66+
67+ /**
68+ * Adds a preprocessor function to the query with a different type of input variables.
69+ * The preprocessor function is called before the query function is called.
70+ */
4871 withPreprocessor < TVars$ = TVars > ( preprocessor : PreprocessorFn < TVars$ , TVars > ) : QueryBuilder < TVars$ , TData , TError , TKey , TTags , TFlags > ;
4972
5073 withPreprocessor < TVars$ = TVars > ( preprocessor : PreprocessorFn < TVars$ , TVars > ) : QueryBuilder < TVars$ , TData , TError , TKey , TTags , TFlags > {
@@ -55,7 +78,18 @@ export class QueryBuilder<
5578 } ) ;
5679 }
5780
81+ /**
82+ * Adds a middleware function to the query.
83+ * The middleware function wraps the query function and
84+ * can be used to modify the input variables, the output data, or the error.
85+ */
5886 withMiddleware ( middleware : MiddlewareFn < TVars , TData , TError , TKey > ) : this;
87+
88+ /**
89+ * Adds a middleware function to the query with overloaded types.
90+ * The middleware function wraps the query function and
91+ * can be used to modify the input variables, the output data, or the error.
92+ */
5993 withMiddleware < TVars$ = TVars , TData$ = TData , TError$ = TError > (
6094 middleware : MiddlewareFn < TVars$ , TData$ , TError$ , TKey > ,
6195 ) : QueryBuilder < TVars$ , TData$ , TError$ , TKey , TTags , TFlags > ;
@@ -74,20 +108,39 @@ export class QueryBuilder<
74108
75109 static tagCacheId = 0 ;
76110
111+ /**
112+ * Adds a tag to the query.
113+ * The tag is used to invalidate or update the query when the tag is updated.
114+ */
77115 withTags ( ...tags : QueryTagOption < TVars , TData , TError , QueryTagObject < TTags > > [ ] ) : this {
78116 return this . withMiddleware ( createTagMiddleware ( tags . flat ( ) , QueryBuilder . tagCacheId ++ ) ) as unknown as this;
79117 }
80118
119+ /**
120+ * Adds a declarative update to the mutation.
121+ * This is used to invalidate or update the queries that were marked with {@link withTags}.
122+ */
81123 withUpdates ( ...tags : QueryTagOption < TVars , TData , TError , QueryUpdateTagObject < TVars , TData , TError , TTags > > [ ] ) : this {
82124 return this . withMiddleware ( createUpdateMiddleware < TVars , TData , TError , TKey , TTags > ( tags ) ) as unknown as this;
83125 }
84126
85127 withTagTypes < TTag extends string , T = unknown > ( ) : QueryBuilder < TVars , TData , TError , TKey , TTags & Record < TTag , T > , TFlags > ;
86128 withTagTypes < TTags$ extends Record < string , unknown > > ( ) : QueryBuilder < TVars , TData , TError , TKey , TTags$ , TFlags > ;
129+
130+ /**
131+ * Declares the type of tags of the query.
132+ * This is used to strongly type the tags which can be helpful when using {@link withUpdates}.
133+ */
87134 withTagTypes ( ) : this {
88135 return this as any ;
89136 }
90137
138+ /**
139+ * Sets the query client for this builder.
140+ * This is required in order to enable {@link client} and {@link tags} interfaces.
141+ * Imperative operations done through those interfaces will be done with the provided query client.
142+ * This method also enables the ability to sync tag invalidation with other browser tabs.
143+ */
91144 withClient (
92145 queryClient : QueryClient ,
93146 { syncTagsWithOtherTabs = true } : { syncTagsWithOtherTabs ?: boolean } = { } ,
@@ -105,16 +158,26 @@ export class QueryBuilder<
105158 return this . withConfig ( { queryClient, syncChannel } ) as any ;
106159 }
107160
161+ /**
162+ * Adds pagination to the query. This is required for methods like {@link useInfiniteQuery} to be available.
163+ */
108164 withPagination (
109165 paginationOptions : BuilderPaginationOptions < TVars , TData , TError , TKey > ,
110166 ) : QueryBuilder < TVars , TData , TError , TKey , TTags , TFlags | 'withPagination' > {
111167 return this . withConfig ( { paginationOptions } as TODO ) ;
112168 }
113169
170+ /**
171+ * Returns a frozen version of this builder.
172+ * The frozen version cannot be modified using `with*` methods.
173+ */
114174 asFrozen ( ) : QueryBuilderFrozen < TVars , TData , TError , TKey , TTags , TFlags > {
115175 return this as any ;
116176 }
117177
178+ /**
179+ * Binds all query methods to this class instance, so that they can be called after object destructuring.
180+ */
118181 asBound ( ) : QueryBuilder < TVars , TData , TError , TKey , TTags , TFlags | 'bound' > {
119182 return this . withConfig ( { bound : true } ) ;
120183 }
0 commit comments