MCPcopy Create free account
hub / github.com/TanStack/query / configureQueryClient

Function configureQueryClient

packages/angular-query/src/providers.ts:27–63  ·  view source on GitHub ↗

* Mounts the injected client, configures server defaults, and connects TransferState hydration.

()

Source from the content-addressed store, hash-verified

25 * Mounts the injected client, configures server defaults, and connects TransferState hydration.
26 */
27function 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

Callers

nothing calls this directly

Calls 8

dehydrateFunction · 0.90
hydrateFunction · 0.90
getDefaultOptionsMethod · 0.80
getMethod · 0.80
setDefaultOptionsMethod · 0.45
removeMethod · 0.45
mountMethod · 0.45
unmountMethod · 0.45

Tested by

no test coverage detected