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

QueryClient.ts

113 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 | false | ((oldData: TData | undefined, newData: TData) => TData)
50​
51/**
52 * The core `InfiniteQueryObserverOptions`, with Solid's `reconcile` option added.
53 *
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 | false | ((oldData: TData | undefined, newData: TData) => TData)
85​
86/**
87 * The default options a `QueryClient` applies to every query, with Solid's `reconcile` option added to
88 * `queries`.
89 *
90 * @template TError - The default type of errors thrown by queries and mutations using this `QueryClient`.
91 */
92export interface DefaultOptions<
93 TError = DefaultError,
94> extends CoreDefaultOptions<TError> {
95 queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
97​
98/**
99 * The config accepted by `new QueryClient(config)`, with Solid's extended {@link DefaultOptions}.
100 */
101export interface QueryClientConfig extends QueryCoreClientConfig {
102 defaultOptions?: DefaultOptions
104​
105/**
106 * The core `@tanstack/query-core` `QueryClient`, typed so its `defaultOptions.queries` accepts Solid's
107 * `reconcile` option.
108 */
109export class QueryClient extends QueryCoreClient {
110 constructor(config: QueryClientConfig = {}) {
111 super(config)
112 }