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

Function dehydrate

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

Source from the content-addressed store, hash-verified

135}
136
137export function dehydrate(
138 client: QueryClient,
139 options: DehydrateOptions = {},
140): DehydratedState {
141 const filterMutation =
142 options.shouldDehydrateMutation ??
143 client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ??
144 defaultShouldDehydrateMutation
145
146 const mutations = client
147 .getMutationCache()
148 .getAll()
149 .flatMap((mutation) =>
150 filterMutation(mutation) ? [dehydrateMutation(mutation)] : [],
151 )
152
153 const filterQuery =
154 options.shouldDehydrateQuery ??
155 client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ??
156 defaultShouldDehydrateQuery
157
158 const shouldRedactErrors =
159 options.shouldRedactErrors ??
160 client.getDefaultOptions().dehydrate?.shouldRedactErrors ??
161 defaultShouldRedactErrors
162
163 const serializeData =
164 options.serializeData ??
165 client.getDefaultOptions().dehydrate?.serializeData ??
166 defaultTransformerFn
167
168 const queries = client
169 .getQueryCache()
170 .getAll()
171 .flatMap((query) =>
172 filterQuery(query)
173 ? [dehydrateQuery(query, serializeData, shouldRedactErrors)]
174 : [],
175 )
176
177 return { mutations, queries }
178}
179
180export function hydrate(
181 client: QueryClient,

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