* Mounts the injected client, configures server defaults, and connects TransferState hydration.
()
| 25 | * Mounts the injected client, configures server defaults, and connects TransferState hydration. |
| 26 | */ |
| 27 | function configureQueryClient() { |
| 28 | const queryClient = inject(QueryClient) |
| 29 | const destroyRef = inject(DestroyRef) |
| 30 | const platformId = inject(PLATFORM_ID) |
| 31 | |
| 32 | if (isPlatformServer(platformId)) { |
| 33 | // DOM emulation can fool core's runtime detection. Apply server defaults to |
| 34 | // this client without changing other clients or global scheduling providers. |
| 35 | const defaults = queryClient.getDefaultOptions() |
| 36 | queryClient.setDefaultOptions({ |
| 37 | ...defaults, |
| 38 | queries: { gcTime: Infinity, retry: false, ...defaults.queries }, |
| 39 | mutations: { gcTime: Infinity, ...defaults.mutations }, |
| 40 | }) |
| 41 | } |
| 42 | const shouldHydrate = inject(INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE) |
| 43 | const hydrationStateKey = inject( |
| 44 | INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY, |
| 45 | ) |
| 46 | |
| 47 | if (inject(DOCUMENT, { optional: true })) { |
| 48 | const transferState = inject(TransferState) |
| 49 | |
| 50 | if (shouldHydrate && isPlatformServer(platformId)) { |
| 51 | transferState.onSerialize(hydrationStateKey, () => dehydrate(queryClient)) |
| 52 | } else if (shouldHydrate && isPlatformBrowser(platformId)) { |
| 53 | const dehydratedState = transferState.get(hydrationStateKey, null) |
| 54 | if (dehydratedState) { |
| 55 | hydrate(queryClient, dehydratedState) |
| 56 | transferState.remove(hydrationStateKey) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | queryClient.mount() |
| 62 | destroyRef.onDestroy(() => queryClient.unmount()) |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Sets up providers necessary to enable TanStack Query functionality for Angular applications. Provides a |
nothing calls this directly
no test coverage detected