Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

queryCache.ts

30 lines986 Bytes

1import { QueryCache as QC } from '@tanstack/query-core'
2import { cloneDeepUnref } from './utils'
3import type {
4 DefaultError,
5 Query,
6 QueryFilters,
7 WithRequired,
8} from '@tanstack/query-core'
9import type { MaybeRefDeep } from './types'
10​
11/**
12 * Vue-aware subclass of `@tanstack/query-core`'s `QueryCache`. `find`/`findAll` also accept a
13 * {@link MaybeRefDeep} filters object, so `ref`s can be passed directly without unwrapping. Access it via
14 * `queryClient.getQueryCache()` β€” `QueryClient` constructs one of these by default.
15 */
16export class QueryCache extends QC {
17 override find<
18 TQueryFnData = unknown,
19 TError = DefaultError,
20 TData = TQueryFnData,
21 >(
22 filters: MaybeRefDeep<WithRequired<QueryFilters, 'queryKey'>>,
23 ): Query<TQueryFnData, TError, TData> | undefined {
24 return super.find(cloneDeepUnref(filters))
25 }
26​
27 override findAll(filters: MaybeRefDeep<QueryFilters> = {}): Array<Query> {
28 return super.findAll(cloneDeepUnref(filters))
29 }