MCPcopy
hub / github.com/TanStack/query / dehydrate

Function dehydrate

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

Source from the content-addressed store, hash-verified

120}
121
122export function dehydrate(
123 client: QueryClient,
124 options: DehydrateOptions = {},
125): DehydratedState {
126 const filterMutation =
127 options.shouldDehydrateMutation ??
128 client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ??
129 defaultShouldDehydrateMutation
130
131 const mutations = client
132 .getMutationCache()
133 .getAll()
134 .flatMap((mutation) =>
135 filterMutation(mutation) ? [dehydrateMutation(mutation)] : [],
136 )
137
138 const filterQuery =
139 options.shouldDehydrateQuery ??
140 client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ??
141 defaultShouldDehydrateQuery
142
143 const shouldRedactErrors =
144 options.shouldRedactErrors ??
145 client.getDefaultOptions().dehydrate?.shouldRedactErrors ??
146 defaultShouldRedactErrors
147
148 const serializeData =
149 options.serializeData ??
150 client.getDefaultOptions().dehydrate?.serializeData ??
151 defaultTransformerFn
152
153 const queries = client
154 .getQueryCache()
155 .getAll()
156 .flatMap((query) =>
157 filterQuery(query)
158 ? [dehydrateQuery(query, serializeData, shouldRedactErrors)]
159 : [],
160 )
161
162 return { mutations, queries }
163}
164
165export function hydrate(
166 client: QueryClient,

Callers 13

persistQueryClientSaveFunction · 0.90
hydration.test.tsxFile · 0.90
useQuery.test.tsxFile · 0.85
query.test.tsxFile · 0.85
HomeFunction · 0.85
getStaticPropsFunction · 0.85
HomeFunction · 0.85

Calls 6

dehydrateMutationFunction · 0.85
dehydrateQueryFunction · 0.85
getDefaultOptionsMethod · 0.80
getMutationCacheMethod · 0.80
getQueryCacheMethod · 0.80
getAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…