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

Function dehydrate

packages/query-core/src/hydration.ts:245–283  ·  view source on GitHub ↗
(
  client: QueryClient,
  options: DehydrateOptions = {},
)

Source from the content-addressed store, hash-verified

243 * ```
244 */
245export function dehydrate(
246 client: QueryClient,
247 options: DehydrateOptions = {},
248): DehydratedState {
249 const filterMutation =
250 options.shouldDehydrateMutation ??
251 client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ??
252 defaultShouldDehydrateMutation
253
254 const mutations = client
255 .getMutationCache()
256 .getAll()
257 .flatMap((mutation) =>
258 filterMutation(mutation) ? [dehydrateMutation(mutation)] : [],
259 )
260
261 const filterQuery =
262 options.shouldDehydrateQuery ??
263 client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ??
264 defaultShouldDehydrateQuery
265
266 const shouldRedactErrors =
267 options.shouldRedactErrors ??
268 client.getDefaultOptions().dehydrate?.shouldRedactErrors
269
270 const serializeData =
271 options.serializeData ?? client.getDefaultOptions().dehydrate?.serializeData
272
273 const queries = client
274 .getQueryCache()
275 .getAll()
276 .flatMap((query) =>
277 filterQuery(query)
278 ? [dehydrateQuery(query, serializeData, shouldRedactErrors)]
279 : [],
280 )
281
282 return { mutations, queries }
283}
284
285/**
286 * Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the

Callers 15

Devtools.test.tsxFile · 0.90
persistQueryClientSaveFunction · 0.90
createQueryFunction · 0.90
persist.test.tsFile · 0.90
configureQueryClientFunction · 0.90
hydration.test.tsxFile · 0.90

Calls 6

dehydrateMutationFunction · 0.85
dehydrateQueryFunction · 0.85
getDefaultOptionsMethod · 0.80
getMutationCacheMethod · 0.80
getQueryCacheMethod · 0.80
getAllMethod · 0.45

Tested by 1

createQueryFunction · 0.72