katanakit-js / QueryService
Class: QueryService
Defined in: src/core/services/query.service.ts:80
QueryService - Singleton para el QueryClient compartido.
Aplica el patrón Singleton: una única instancia mantiene el QueryClient global que comparten todos los adaptadores de framework (browser). En SSR, usa QueryClientFactory.create para un cliente por petición.
Example
const client = QueryService.getInstance().useGetClient();
await client.invalidateQueries({ queryKey: ["users"] });Methods
useGetClient()
useGetClient(): QueryClient;Defined in: src/core/services/query.service.ts:112
Returns the shared QueryClient, creating one on first call.
This is a process-global instance: it is the right default in the browser, but on the server it would leak cached data across requests. Use QueryClientFactory.create per request when running under SSR.
Returns
The shared QueryClient.
useInit()
useInit(config?): QueryClient;Defined in: src/core/services/query.service.ts:124
Replaces the shared QueryClient with a configured instance. The previous client's caches are cleared before swapping.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | QueryClientConfig | TanStack QueryClientConfig (caches, default options). |
Returns
The newly created QueryClient.
useSafeQueryFn()
useSafeQueryFn<T>(fn): (context) => Promise<T>;Defined in: src/core/services/query.service.ts:142
Bridges a KatanaKit Safe Result fetcher into a TanStack queryFn.
TanStack expects queryFn to resolve with data and throw on failure; KatanaKit returns { data, error, ok }. This adapter unwraps the Safe Result so the two fit together. Throws a real Error (with status) so instanceof checks and error boundaries work.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The resolved data type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | (context) => Promise<FetchResult<T>> | A function returning a Safe Result (e.g. () => useGetApi(...)). |
Returns
A queryFn that throws on error.
(context) => Promise<T>
getInstance()
static getInstance(): QueryService;Defined in: src/core/services/query.service.ts:96
Obtiene la instancia única del QueryService (Singleton).
Returns
QueryService
La instancia única de QueryService.