@@ -100,9 +100,6 @@ type FetchQueryOtherOptions<T, E = DefaultError> = Omit<
100100 'queryKey' | 'queryFn'
101101>
102102
103- /** Result that includes both success and error so it can be cached by RQ */
104- type ErrorsAllowed < T , E > = { type : 'success' ; data : T } | { type : 'error' ; data : E }
105-
106103export const getUseApiQuery =
107104 < A extends ApiClient > ( api : A ) =>
108105 < M extends string & keyof A > (
@@ -123,35 +120,6 @@ export const getUseApiQuery =
123120 } )
124121 }
125122
126- /**
127- * Our version of `useQueries`, but with the key difference that all queries in
128- * a given call are using the same API method, and therefore all have the same
129- * request and response (`Params` and `Result`) types. Otherwise the types would
130- * be (perhaps literally) impossible.
131- */
132- export const getUseApiQueries =
133- < A extends ApiClient > ( api : A ) =>
134- < M extends string & keyof A > (
135- method : M ,
136- paramsArray : Params < A [ M ] > [ ] ,
137- options : UseQueryOtherOptions < Result < A [ M ] > , ApiError > = { }
138- ) => {
139- return useQueries ( {
140- queries : paramsArray . map (
141- ( params ) =>
142- ( {
143- queryKey : [ method , params ] ,
144- queryFn : ( { signal } ) =>
145- api [ method ] ( params , { signal } ) . then ( handleResult ( method ) ) ,
146- throwOnError : ( err : ApiError ) => err . statusCode === 404 ,
147- ...options ,
148- // Add params to the result for reassembly after the queries are returned
149- select : ( data ) => ( { ...data , params } ) ,
150- } ) satisfies UseQueryOptions < Result < A [ M ] > & { params : Params < A [ M ] > } , ApiError >
151- ) ,
152- } )
153- }
154-
155123export const getUsePrefetchedApiQuery =
156124 < A extends ApiClient > ( api : A ) =>
157125 < M extends string & keyof A > (
@@ -189,6 +157,9 @@ Ensure the following:
189157
190158const ERRORS_ALLOWED = 'errors-allowed'
191159
160+ /** Result that includes both success and error so it can be cached by RQ */
161+ type ErrorsAllowed < T , E > = { type : 'success' ; data : T } | { type : 'error' ; data : E }
162+
192163/**
193164 * Variant of `getUseApiQuery` that allows error responses as a valid result,
194165 * which importantly means they can be cached by RQ. This means we can prefetch
@@ -238,6 +209,35 @@ export const getUseApiMutation =
238209 ...options ,
239210 } )
240211
212+ /**
213+ * Our version of `useQueries`, but with the key difference that all queries in
214+ * a given call are using the same API method, and therefore all have the same
215+ * request and response (`Params` and `Result`) types. Otherwise the types would
216+ * be (perhaps literally) impossible.
217+ */
218+ export const getUseApiQueries =
219+ < A extends ApiClient > ( api : A ) =>
220+ < M extends string & keyof A > (
221+ method : M ,
222+ paramsArray : Params < A [ M ] > [ ] ,
223+ options : UseQueryOtherOptions < Result < A [ M ] > , ApiError > = { }
224+ ) => {
225+ return useQueries ( {
226+ queries : paramsArray . map (
227+ ( params ) =>
228+ ( {
229+ queryKey : [ method , params ] ,
230+ queryFn : ( { signal } ) =>
231+ api [ method ] ( params , { signal } ) . then ( handleResult ( method ) ) ,
232+ throwOnError : ( err : ApiError ) => err . statusCode === 404 ,
233+ ...options ,
234+ // Add params to the result for reassembly after the queries are returned
235+ select : ( data ) => ( { ...data , params } ) ,
236+ } ) satisfies UseQueryOptions < Result < A [ M ] > & { params : Params < A [ M ] > } , ApiError >
237+ ) ,
238+ } )
239+ }
240+
241241export const wrapQueryClient = < A extends ApiClient > ( api : A , queryClient : QueryClient ) => ( {
242242 /**
243243 * Note that we only take a single argument, `method`, rather than allowing
0 commit comments