import { QueryClient } from '@tanstack/react-query'; /** * Единый QueryClient приложения. Живёт в модуле (а не в main.tsx), чтобы * не-React код — например стор шлюза — мог инвалидировать кэш REST-запросов. */ let client: QueryClient | null = null; export function getQueryClient(): QueryClient { client ??= new QueryClient({ defaultOptions: { queries: { staleTime: 30_000, refetchOnWindowFocus: false, retry: 1, }, }, }); return client; } /** Только для тестов: подменяет общий клиент изолированным. */ export function setQueryClient(next: QueryClient | null): void { client = next; }