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

QueryClient.ts

85 lines2.4 KB

1import { QueryClient as QueryCoreClient } from '@tanstack/query-core'
2import type {
3 DefaultOptions as CoreDefaultOptions,
4 DefaultError,
5 OmitKeyof,
6 QueryClientConfig as QueryCoreClientConfig,
7 InfiniteQueryObserverOptions as QueryCoreInfiniteQueryObserverOptions,
8 QueryObserverOptions as QueryCoreObserverOptions,
9 QueryKey,
10} from '@tanstack/query-core'
11​
12export interface QueryObserverOptions<
13 TQueryFnData = unknown,
14 TError = DefaultError,
15 TData = TQueryFnData,
16 TQueryData = TQueryFnData,
17 TQueryKey extends QueryKey = QueryKey,
18 TPageParam = never,
19> extends OmitKeyof<
20 QueryCoreObserverOptions<
21 TQueryFnData,
22 TError,
23 TData,
24 TQueryData,
25 TQueryKey,
26 TPageParam
27 >,
28 'structuralSharing'
29 > {
30 /**
31 * Set this to a reconciliation key to enable reconciliation between query results.
32 * Set this to `false` to disable reconciliation between query results.
33 * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
34 * Defaults reconciliation to false.
35 */
36 reconcile?:
37 | string
38 | false
39 | ((oldData: TData | undefined, newData: TData) => TData)
41​
42export interface InfiniteQueryObserverOptions<
43 TQueryFnData = unknown,
44 TError = DefaultError,
45 TData = TQueryFnData,
46 TQueryData = TQueryFnData,
47 TQueryKey extends QueryKey = QueryKey,
48 TPageParam = unknown,
49> extends OmitKeyof<
50 QueryCoreInfiniteQueryObserverOptions<
51 TQueryFnData,
52 TError,
53 TData,
54 TQueryData,
55 TQueryKey,
56 TPageParam
57 >,
58 'structuralSharing'
59 > {
60 /**
61 * Set this to a reconciliation key to enable reconciliation between query results.
62 * Set this to `false` to disable reconciliation between query results.
63 * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
64 * Defaults reconciliation to false.
65 */
66 reconcile?:
67 | string
68 | false
69 | ((oldData: TData | undefined, newData: TData) => TData)
71​
72export interface DefaultOptions<TError = DefaultError>
73 extends CoreDefaultOptions<TError> {
74 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
76​
77export interface QueryClientConfig extends QueryCoreClientConfig {
78 defaultOptions?: DefaultOptions
80​
81export class QueryClient extends QueryCoreClient {
82 constructor(config: QueryClientConfig = {}) {
83 super(config)
84 }