| 205 | * ``` |
| 206 | */ |
| 207 | export 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 |