Open History to see the last commit
1import { QueryClient as QueryCoreClient } from '@tanstack/query-core'
2import type {
3 DefaultOptions as CoreDefaultOptions,
4 DefaultError,
5 InfiniteData,
6 InfiniteQueryMode,
7 InfiniteQueryPageParamsOptions,
8 OmitKeyof,
9 QueryClientConfig as QueryCoreClientConfig,
10 QueryObserverOptions as QueryCoreObserverOptions,
11 QueryKey,
12} from '@tanstack/query-core'
13β
14/**
15 * The core `QueryObserverOptions`, with Solid's `reconcile` option added.
16 * @template TQueryFnData - The type your `queryFn` resolves to.
17 * @template TError - The type of errors your `queryFn` may throw.
18 * @template TData - The type `data` ends up as after `select` runs.
19 * @template TQueryData - The type of the data actually held in the query cache.
20 * @template TQueryKey - The type of your `queryKey`.
21 * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page, when this type
22 * is shared with an infinite query's observer 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 results.
44 * Set this to `false` to disable reconciliation between query results.
45 * 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.
46 * Defaults reconciliation to false.
47 */
48 reconcile?:
49 string | false | ((oldData: TData | undefined, newData: TData) => TData)
50}
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 type InfiniteQueryObserverOptions<
61 TQueryFnData = unknown,
62 TError = DefaultError,
63 TData = TQueryFnData,
64 TQueryKey extends QueryKey = QueryKey,
65 TPageParam = unknown,
66 TMode extends InfiniteQueryMode | undefined = undefined,
67> = OmitKeyof<
68 QueryCoreObserverOptions<
69 TQueryFnData,
70 TError,
71 TData,
72 InfiniteData<TQueryFnData, TPageParam>,
73 TQueryKey,
74 TPageParam
75 >,
76 'structuralSharing'
77> &
78 InfiniteQueryPageParamsOptions<TQueryFnData, TPageParam, TMode> & {
79 /**
80 * Set this to a reconciliation key to enable reconciliation between query results.
81 * Set this to `false` to disable reconciliation between query results.
82 * 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.
83 * Defaults reconciliation to false.
84 */
85 reconcile?:
86 string | false | ((oldData: TData | undefined, newData: TData) => TData)
87 }
88β
89/**
90 * The default options a `QueryClient` applies to every query, with Solid's `reconcile` option added to
91 * `queries`.
92 * @template TError - The default type of errors thrown by queries and mutations using this `QueryClient`.
93 */
94export interface DefaultOptions<
95 TError = DefaultError,
96> extends CoreDefaultOptions<TError> {
97 /**
98 * Default options applied to every query, unless overridden per-query, including Solid's
99 * `reconcile` option.
100 */
101 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
102}
103β
104/**
105 * The config accepted by `new QueryClient(config)`, with Solid's extended {@link DefaultOptions}.
106 */
107export interface QueryClientConfig extends QueryCoreClientConfig {
108 /**
109 * The default options of the queries and mutations of this `QueryClient`.
110 */
111 defaultOptions?: DefaultOptions
112}
113β
114/**
115 * The core `@tanstack/query-core` `QueryClient`, typed so its `defaultOptions.queries` accepts Solid's
116 * `reconcile` option.
117 */
118export class QueryClient extends QueryCoreClient {
119 constructor(config: QueryClientConfig = {}) {
120 super(config)
121 }
122}