| 243 | * ``` |
| 244 | */ |
| 245 | export 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 |