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