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

Function dehydrate

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

Source from the content-addressed store, hash-verified

205 * ```
206 */
207export function dehydrate(
208 client: QueryClient,
209 options: DehydrateOptions = {},
210): DehydratedState {
211 const filterMutation =
212 options.shouldDehydrateMutation ??
213 client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ??
214 defaultShouldDehydrateMutation
215
216 const mutations = client
217 .getMutationCache()
218 .getAll()
219 .flatMap((mutation) =>
220 filterMutation(mutation) ? [dehydrateMutation(mutation)] : [],
221 )
222
223 const filterQuery =
224 options.shouldDehydrateQuery ??
225 client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ??
226 defaultShouldDehydrateQuery
227
228 const shouldRedactErrors =
229 options.shouldRedactErrors ??
230 client.getDefaultOptions().dehydrate?.shouldRedactErrors
231
232 const serializeData =
233 options.serializeData ?? client.getDefaultOptions().dehydrate?.serializeData
234
235 const queries = client
236 .getQueryCache()
237 .getAll()
238 .flatMap((query) =>
239 filterQuery(query)
240 ? [dehydrateQuery(query, serializeData, shouldRedactErrors)]
241 : [],
242 )
243
244 return { mutations, queries }
245}
246
247/**
248 * Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the

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