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

QueryClient.ts

83 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 TQueryKey extends QueryKey = QueryKey,
47 TPageParam = unknown,
48> extends OmitKeyof<
49 QueryCoreInfiniteQueryObserverOptions<
50 TQueryFnData,
51 TError,
52 TData,
53 TQueryKey,
54 TPageParam
55 >,
56 'structuralSharing'
57 > {
58 /**
59 * Set this to a reconciliation key to enable reconciliation between query results.
60 * Set this to `false` to disable reconciliation between query results.
61 * 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.
62 * Defaults reconciliation to false.
63 */
64 reconcile?:
65 | string
66 | false
67 | ((oldData: TData | undefined, newData: TData) => TData)
69​
70export interface DefaultOptions<TError = DefaultError>
71 extends CoreDefaultOptions<TError> {
72 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
74​
75export interface QueryClientConfig extends QueryCoreClientConfig {
76 defaultOptions?: DefaultOptions
78​
79export class QueryClient extends QueryCoreClient {
80 constructor(config: QueryClientConfig = {}) {
81 super(config)
82 }