@@ -115,8 +115,23 @@ export function qraftAPIClient<
115115) : APIBasicQueryClientServices < Services , Callbacks > ;
116116
117117/**
118- * Creates a basic API Client which contains only "fetch" like
119- * operations without any state management using QueryClient.
118+ * Creates a basic API Client which contains all hooks and methods
119+ * that don't require an explicitly provided QueryClient.
120+ * Hooks like `useQuery` and `useMutation` will automatically retrieve
121+ * the QueryClient from the `<QueryClientProvider />` context.
122+ *
123+ * @example Fetching data with QueryClient from context
124+ * ```ts
125+ * const api = qraftAPIClient(services, callbacks, {
126+ * requestFn: requestFn,
127+ * baseUrl: 'https://api.example.com',
128+ * });
129+ *
130+ * // QueryClient will be retrieved from React context
131+ * api.service.operation.useQuery({
132+ * parameters: { path: { id: 1 } },
133+ * });
134+ * ```
120135 *
121136 * @example Fetching data without QueryClient
122137 * ```ts
@@ -140,8 +155,17 @@ export function qraftAPIClient<
140155) : APIBasicClientServices < Services , Callbacks > ;
141156
142157/**
143- * Creates a utility API Client which contains only utility operations
144- * such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.
158+ * Creates a utility API Client which contains utility operations
159+ * such as `getQueryKey`, `getInfiniteQueryKey`, `getMutationKey` and state hooks
160+ * like `useIsFetching` and `useMutationData`.
161+ *
162+ * @example Using state hooks
163+ * ```ts
164+ * const api = qraftAPIClient(services, callbacks);
165+ *
166+ * // Check if any query is currently fetching
167+ * const isFetching = api.service.operation.useIsFetching();
168+ * ```
145169 *
146170 * @example Getting query keys with utility client
147171 * ```ts
@@ -241,7 +265,17 @@ export function qraftAPIClient<
241265 callbackName !== 'operationInvokeFn' &&
242266 callbackName !== 'getQueryKey' &&
243267 callbackName !== 'getMutationKey' &&
244- callbackName !== 'getInfiniteQueryKey'
268+ callbackName !== 'getInfiniteQueryKey' &&
269+ callbackName !== 'useInfiniteQuery' &&
270+ callbackName !== 'useQueries' &&
271+ callbackName !== 'useQuery' &&
272+ callbackName !== 'useSuspenseInfiniteQuery' &&
273+ callbackName !== 'useSuspenseQueries' &&
274+ callbackName !== 'useSuspenseQuery' &&
275+ callbackName !== 'useIsFetching' &&
276+ callbackName !== 'useMutation' &&
277+ callbackName !== 'useIsMutating' &&
278+ callbackName !== 'useMutationState'
245279 )
246280 if ( ! options || ! ( 'queryClient' in options && options . queryClient ) )
247281 throw new Error (
@@ -331,7 +365,7 @@ type OperationDeclaration = {
331365 Record <
332366 | QueryOperationCallbacks
333367 | QueryOperationStateCallbacks
334- | MutationOperationCallbacks
368+ | MutationOperationHookCallbacks
335369 | MutationOperationStateCallbacks
336370 | UtilityOperationCallbacks ,
337371 any
@@ -356,15 +390,8 @@ export type UnionServiceOperationsDeclaration<Services> =
356390 | OperationsDeclaration < Services >
357391 | OperationDeclaration ;
358392
359- type QueryOperationCallbacks = Extract <
393+ type QueryOperationHookCallbacks = Extract <
360394 keyof ServiceMethods ,
361- | 'fetchInfiniteQuery'
362- | 'fetchQuery'
363- | 'prefetchInfiniteQuery'
364- | 'prefetchQuery'
365- | 'refetchQueries'
366- | 'ensureQueryData'
367- | 'ensureInfiniteQueryData'
368395 | 'useInfiniteQuery'
369396 | 'useQueries'
370397 | 'useQuery'
@@ -373,45 +400,75 @@ type QueryOperationCallbacks = Extract<
373400 | 'useSuspenseQuery'
374401> ;
375402
376- type QueryOperationStateCallbacks = Extract <
403+ type QueryOperationCallbacks =
404+ | Extract <
405+ keyof ServiceMethods ,
406+ | 'fetchInfiniteQuery'
407+ | 'fetchQuery'
408+ | 'prefetchInfiniteQuery'
409+ | 'prefetchQuery'
410+ | 'refetchQueries'
411+ | 'ensureQueryData'
412+ | 'ensureInfiniteQueryData'
413+ >
414+ | QueryOperationHookCallbacks ;
415+
416+ type QueryOperationStateHookCallbacks = Extract <
377417 keyof ServiceMethods ,
378- | 'cancelQueries'
379- | 'getInfiniteQueryData'
380- | 'getInfiniteQueryState'
381- | 'getQueriesData'
382- | 'getQueryData'
383- | 'getQueryState'
384- | 'invalidateQueries'
385- | 'isFetching'
386- | 'removeQueries'
387- | 'resetQueries'
388- | 'setInfiniteQueryData'
389- | 'setQueriesData'
390- | 'setQueryData'
391- | 'useIsFetching'
418+ 'useIsFetching'
392419> ;
393420
394- type MutationOperationCallbacks = Extract < keyof ServiceMethods , 'useMutation' > ;
421+ type QueryOperationStateCallbacks =
422+ | Extract <
423+ keyof ServiceMethods ,
424+ | 'cancelQueries'
425+ | 'getInfiniteQueryData'
426+ | 'getInfiniteQueryState'
427+ | 'getQueriesData'
428+ | 'getQueryData'
429+ | 'getQueryState'
430+ | 'invalidateQueries'
431+ | 'isFetching'
432+ | 'removeQueries'
433+ | 'resetQueries'
434+ | 'setInfiniteQueryData'
435+ | 'setQueriesData'
436+ | 'setQueryData'
437+ >
438+ | QueryOperationStateHookCallbacks ;
395439
396- type MutationOperationStateCallbacks = Extract <
440+ type MutationOperationHookCallbacks = Extract <
397441 keyof ServiceMethods ,
398- 'isMutating' | 'useIsMutating' | 'useMutationState '
442+ 'useMutation '
399443> ;
400444
445+ type MutationOperationStateHookCallbacks = Extract <
446+ keyof ServiceMethods ,
447+ 'useIsMutating' | 'useMutationState'
448+ > ;
449+
450+ type MutationOperationStateCallbacks =
451+ | Extract < keyof ServiceMethods , 'isMutating' >
452+ | MutationOperationStateHookCallbacks ;
453+
401454type InvokeOperationCallback = Extract <
402455 keyof typeof operationInvokeModule ,
403456 'operationInvokeFn'
404457> ;
405458
406459type UtilityOperationCallbacks = Extract <
407460 keyof ServiceMethods ,
408- 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'
461+ | 'getQueryKey'
462+ | 'getInfiniteQueryKey'
463+ | 'getMutationKey'
464+ | QueryOperationStateHookCallbacks
465+ | MutationOperationStateHookCallbacks
409466> ;
410467
411468type OperationCallbackList =
412469 | QueryOperationCallbacks
413470 | QueryOperationStateCallbacks
414- | MutationOperationCallbacks
471+ | MutationOperationHookCallbacks
415472 | MutationOperationStateCallbacks
416473 | InvokeOperationCallback
417474 | UtilityOperationCallbacks ;
@@ -458,7 +515,15 @@ export type APIBasicClientServices<
458515 Callbacks extends PartialServiceMethods ,
459516> = ServicesFilteredByCallbacks <
460517 Services ,
461- Extract < keyof Callbacks , InvokeOperationCallback | UtilityOperationCallbacks >
518+ Extract <
519+ keyof Callbacks ,
520+ | InvokeOperationCallback
521+ | UtilityOperationCallbacks
522+ | QueryOperationHookCallbacks
523+ | QueryOperationStateHookCallbacks
524+ | MutationOperationStateHookCallbacks
525+ | MutationOperationHookCallbacks
526+ >
462527> ;
463528
464529export type APIUtilityClientServices <
0 commit comments