| 135 | } |
| 136 | |
| 137 | export 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 | |
| 180 | export function hydrate( |
| 181 | client: QueryClient, |