MCPcopy Index your code
hub / github.com/TanStack/query / restoreQueries

Function restoreQueries

packages/query-persist-client-core/src/createPersister.ts:250–291  ·  view source on GitHub ↗
(
    queryClient: QueryClient,
    filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},
  )

Source from the content-addressed store, hash-verified

248 }
249
250 async function restoreQueries(
251 queryClient: QueryClient,
252 filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},
253 ): Promise<void> {
254 const { exact, queryKey } = filters
255
256 if (storage?.entries) {
257 const entries = await storage.entries()
258 for (const [key, value] of entries) {
259 if (key.startsWith(prefix)) {
260 const persistedQuery = await deserialize(value)
261
262 if (isExpiredOrBusted(persistedQuery)) {
263 await storage.removeItem(key)
264 continue
265 }
266
267 if (queryKey) {
268 if (exact) {
269 if (persistedQuery.queryHash !== hashKey(queryKey)) {
270 continue
271 }
272 } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {
273 continue
274 }
275 }
276
277 queryClient.setQueryData(
278 persistedQuery.queryKey,
279 persistedQuery.state.data,
280 {
281 updatedAt: persistedQuery.state.dataUpdatedAt,
282 },
283 )
284 }
285 }
286 } else if (process.env.NODE_ENV === 'development') {
287 throw new Error(
288 'Provided storage does not implement `entries` method. Restoration of all stored entries is not possible without ability to iterate over storage items.',
289 )
290 }
291 }
292
293 return {
294 persisterFn,

Callers

nothing calls this directly

Calls 4

hashKeyFunction · 0.90
partialMatchKeyFunction · 0.90
isExpiredOrBustedFunction · 0.85
setQueryDataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…