@@ -9,10 +9,6 @@ import {
99 hashKey ,
1010 queryOptions ,
1111 useMutation ,
12- useQuery ,
13- type FetchQueryOptions ,
14- type InvalidateQueryFilters ,
15- type QueryClient ,
1612 type QueryKey ,
1713 type UseMutationOptions ,
1814 type UseQueryOptions ,
@@ -89,15 +85,6 @@ type UseQueryOtherOptions<T> = Omit<
8985 'queryKey' | 'queryFn' | 'initialData'
9086>
9187
92- /**
93- * `queryKey` and `queryFn` are always constructed by our helper hooks, so we
94- * only allow the rest of the options.
95- */
96- type FetchQueryOtherOptions < T > = Omit <
97- FetchQueryOptions < T , ApiError > ,
98- 'queryKey' | 'queryFn'
99- >
100-
10188export const getApiQueryOptions =
10289 < A extends ApiClient > ( api : A ) =>
10390 < M extends string & keyof A > (
@@ -177,17 +164,6 @@ export const getListQueryOptionsFn =
177164 }
178165 }
179166
180- export const getUsePrefetchedApiQuery =
181- < A extends ApiClient > ( api : A ) =>
182- < M extends string & keyof A > (
183- method : M ,
184- params : Params < A [ M ] > ,
185- options : UseQueryOtherOptions < Result < A [ M ] > > = { }
186- ) => {
187- const qOptions = getApiQueryOptions ( api ) ( method , params , options )
188- return ensurePrefetched ( useQuery ( qOptions ) , qOptions . queryKey )
189- }
190-
191167const prefetchError = ( key ?: QueryKey ) =>
192168 `Expected query to be prefetched.
193169Key: ${ key ? hashKey ( key ) : '<unknown>' }
@@ -257,47 +233,6 @@ export const getUseApiMutation =
257233 ...options ,
258234 } )
259235
260- export const wrapQueryClient = < A extends ApiClient > ( api : A , queryClient : QueryClient ) => ( {
261- /**
262- * Note that we only take a single argument, `method`, rather than allowing
263- * the full query key `[query, params]` to be specified. This is to avoid
264- * accidentally overspecifying and therefore failing to match the desired
265- * query. The params argument can be added back in if we ever have a use case
266- * for it.
267- *
268- * Passing no arguments will invalidate all queries.
269- */
270- invalidateQueries : < M extends keyof A > ( method ?: M , filters ?: InvalidateQueryFilters ) =>
271- queryClient . invalidateQueries ( method ? { queryKey : [ method ] , ...filters } : undefined ) ,
272- setQueryData : < M extends keyof A > ( method : M , params : Params < A [ M ] > , data : Result < A [ M ] > ) =>
273- queryClient . setQueryData ( [ method , params ] , data ) ,
274- setQueryDataErrorsAllowed : < M extends keyof A > (
275- method : M ,
276- params : Params < A [ M ] > ,
277- data : ErrorsAllowed < Result < A [ M ] > , ApiError >
278- ) => queryClient . setQueryData ( [ method , params , ERRORS_ALLOWED ] , data ) ,
279- fetchQuery : < M extends string & keyof A > (
280- method : M ,
281- params : Params < A [ M ] > ,
282- options : FetchQueryOtherOptions < Result < A [ M ] > > = { }
283- ) =>
284- queryClient . fetchQuery ( {
285- queryKey : [ method , params ] ,
286- queryFn : ( ) => api [ method ] ( params ) . then ( handleResult ( method ) ) ,
287- ...options ,
288- } ) ,
289- prefetchQuery : < M extends string & keyof A > (
290- method : M ,
291- params : Params < A [ M ] > ,
292- options : FetchQueryOtherOptions < Result < A [ M ] > > = { }
293- ) =>
294- queryClient . prefetchQuery ( {
295- queryKey : [ method , params ] ,
296- queryFn : ( ) => api [ method ] ( params ) . then ( handleResult ( method ) ) ,
297- ...options ,
298- } ) ,
299- } )
300-
301236/*
3022371. what's up with [method, params]?
303238
0 commit comments