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

QueryClient.ts

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