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

QueryClient.ts

121 lines4.1 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​
12/**
13 * The core `QueryObserverOptions`, with Solid's `reconcile` option added.
14 * @template TQueryFnData - The type your `queryFn` resolves to.
15 * @template TError - The type of errors your `queryFn` may throw.
16 * @template TData - The type `data` ends up as after `select` runs.
17 * @template TQueryData - The type of the data actually held in the query cache.
18 * @template TQueryKey - The type of your `queryKey`.
19 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page, when this type
20 * is shared with an infinite query's observer options. Defaults to `never` for regular queries.
21 */
22export interface QueryObserverOptions<
23 TQueryFnData = unknown,
24 TError = DefaultError,
25 TData = TQueryFnData,
26 TQueryData = TQueryFnData,
27 TQueryKey extends QueryKey = QueryKey,
28 TPageParam = never,
29> extends OmitKeyof<
30 QueryCoreObserverOptions<
31 TQueryFnData,
32 TError,
33 TData,
34 TQueryData,
35 TQueryKey,
36 TPageParam
37 >,
38 'structuralSharing'
39> {
40 /**
41 * Set this to a reconciliation key to enable reconciliation between query results.
42 * Set this to `false` to disable reconciliation between query results.
43 * 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.
44 * Defaults reconciliation to false.
45 */
46 reconcile?:
47 | string
48 | false
49 | ((oldData: TData | undefined, newData: TData) => TData)
51​
52/**
53 * The core `InfiniteQueryObserverOptions`, with Solid's `reconcile` option added.
54 * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
55 * @template TError - The type of errors your `queryFn` may throw.
56 * @template TData - The type `data` ends up as after `select` runs.
57 * @template TQueryKey - The type of your `queryKey`.
58 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
59 */
60export interface InfiniteQueryObserverOptions<
61 TQueryFnData = unknown,
62 TError = DefaultError,
63 TData = TQueryFnData,
64 TQueryKey extends QueryKey = QueryKey,
65 TPageParam = unknown,
66> extends OmitKeyof<
67 QueryCoreInfiniteQueryObserverOptions<
68 TQueryFnData,
69 TError,
70 TData,
71 TQueryKey,
72 TPageParam
73 >,
74 'structuralSharing'
75> {
76 /**
77 * Set this to a reconciliation key to enable reconciliation between query results.
78 * Set this to `false` to disable reconciliation between query results.
79 * 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.
80 * Defaults reconciliation to false.
81 */
82 reconcile?:
83 | string
84 | false
85 | ((oldData: TData | undefined, newData: TData) => TData)
87​
88/**
89 * The default options a `QueryClient` applies to every query, with Solid's `reconcile` option added to
90 * `queries`.
91 * @template TError - The default type of errors thrown by queries and mutations using this `QueryClient`.
92 */
93export interface DefaultOptions<
94 TError = DefaultError,
95> extends CoreDefaultOptions<TError> {
96 /**
97 * Default options applied to every query, unless overridden per-query, including Solid's
98 * `reconcile` option.
99 */
100 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
102​
103/**
104 * The config accepted by `new QueryClient(config)`, with Solid's extended {@link DefaultOptions}.
105 */
106export interface QueryClientConfig extends QueryCoreClientConfig {
107 /**
108 * The default options of the queries and mutations of this `QueryClient`.
109 */
110 defaultOptions?: DefaultOptions
112​
113/**
114 * The core `@tanstack/query-core` `QueryClient`, typed so its `defaultOptions.queries` accepts Solid's
115 * `reconcile` option.
116 */
117export class QueryClient extends QueryCoreClient {
118 constructor(config: QueryClientConfig = {}) {
119 super(config)
120 }