@tanstack/solid-query 5.104.0 → 5.104.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dev.cjs +49 -21
- package/build/dev.js +49 -21
- package/build/index.d.cts +37 -88
- package/build/index.d.cts.map +1 -1
- package/build/index.d.ts +37 -88
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/package.json +6 -5
- package/src/QueryClient.ts +13 -5
- package/src/QueryClientProvider.tsx +9 -4
- package/src/infiniteQueryOptions.ts +2 -8
- package/src/isRestoring.ts +0 -1
- package/src/mutationOptions.ts +2 -6
- package/src/queryOptions.ts +2 -8
- package/src/types.ts +11 -18
- package/src/useBaseQuery.ts +36 -2
- package/src/useInfiniteQuery.ts +8 -13
- package/src/useIsFetching.ts +0 -2
- package/src/useIsMutating.ts +0 -2
- package/src/useMutation.ts +0 -6
- package/src/useMutationState.ts +7 -4
- package/src/useQueries.ts +0 -2
- package/src/useQuery.ts +2 -11
package/src/QueryClient.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The core `QueryObserverOptions`, with Solid's `reconcile` option added.
|
|
14
|
-
*
|
|
15
14
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
16
15
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
17
16
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -45,12 +44,13 @@ export interface QueryObserverOptions<
|
|
|
45
44
|
* Defaults reconciliation to false.
|
|
46
45
|
*/
|
|
47
46
|
reconcile?:
|
|
48
|
-
|
|
47
|
+
| string
|
|
48
|
+
| false
|
|
49
|
+
| ((oldData: TData | undefined, newData: TData) => TData)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* The core `InfiniteQueryObserverOptions`, with Solid's `reconcile` option added.
|
|
53
|
-
*
|
|
54
54
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
55
55
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
56
56
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -80,18 +80,23 @@ export interface InfiniteQueryObserverOptions<
|
|
|
80
80
|
* Defaults reconciliation to false.
|
|
81
81
|
*/
|
|
82
82
|
reconcile?:
|
|
83
|
-
|
|
83
|
+
| string
|
|
84
|
+
| false
|
|
85
|
+
| ((oldData: TData | undefined, newData: TData) => TData)
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
/**
|
|
87
89
|
* The default options a `QueryClient` applies to every query, with Solid's `reconcile` option added to
|
|
88
90
|
* `queries`.
|
|
89
|
-
*
|
|
90
91
|
* @template TError - The default type of errors thrown by queries and mutations using this `QueryClient`.
|
|
91
92
|
*/
|
|
92
93
|
export interface DefaultOptions<
|
|
93
94
|
TError = DefaultError,
|
|
94
95
|
> extends CoreDefaultOptions<TError> {
|
|
96
|
+
/**
|
|
97
|
+
* Default options applied to every query, unless overridden per-query, including Solid's
|
|
98
|
+
* `reconcile` option.
|
|
99
|
+
*/
|
|
95
100
|
queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -99,6 +104,9 @@ export interface DefaultOptions<
|
|
|
99
104
|
* The config accepted by `new QueryClient(config)`, with Solid's extended {@link DefaultOptions}.
|
|
100
105
|
*/
|
|
101
106
|
export interface QueryClientConfig extends QueryCoreClientConfig {
|
|
107
|
+
/**
|
|
108
|
+
* The default options of the queries and mutations of this `QueryClient`.
|
|
109
|
+
*/
|
|
102
110
|
defaultOptions?: DefaultOptions
|
|
103
111
|
}
|
|
104
112
|
|
|
@@ -19,11 +19,11 @@ const queryClientContextError =
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The `useQueryClient` primitive returns the current `QueryClient` instance.
|
|
22
|
-
*
|
|
23
22
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
24
23
|
* be used.
|
|
25
24
|
* @returns The current `QueryClient` instance.
|
|
26
|
-
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
25
|
+
* @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
26
|
+
* component tree.
|
|
27
27
|
*/
|
|
28
28
|
export const useQueryClient = (queryClient?: QueryClient) => {
|
|
29
29
|
if (queryClient) {
|
|
@@ -38,6 +38,12 @@ export const useQueryClient = (queryClient?: QueryClient) => {
|
|
|
38
38
|
return client()
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the `QueryClient` to use: the given one, or else the one from the nearest
|
|
43
|
+
* `QueryClientProvider`.
|
|
44
|
+
* @param queryClient - Returns a custom `QueryClient`, if any.
|
|
45
|
+
* @returns An accessor that returns the resolved client. It throws if neither client is available.
|
|
46
|
+
*/
|
|
41
47
|
export const useQueryClientResolver = (
|
|
42
48
|
queryClient?: Accessor<QueryClient | undefined>,
|
|
43
49
|
): Accessor<QueryClient> => {
|
|
@@ -78,9 +84,8 @@ export type QueryClientProviderProps = {
|
|
|
78
84
|
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
79
85
|
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
80
86
|
* comes back online).
|
|
81
|
-
*
|
|
87
|
+
* @param props - The `client` to provide, and the `children` that get access to it.
|
|
82
88
|
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
83
|
-
*
|
|
84
89
|
* @example
|
|
85
90
|
* ```tsx
|
|
86
91
|
* import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
|
|
@@ -14,7 +14,6 @@ import type { Accessor } from 'solid-js'
|
|
|
14
14
|
* object (its parameter type is `ReturnType<UndefinedInitialDataInfiniteOptions<...>>`, i.e. this `Accessor`
|
|
15
15
|
* called); Solid's reactivity applies where the result is consumed instead, e.g.
|
|
16
16
|
* `useInfiniteQuery(() => options)`.
|
|
17
|
-
*
|
|
18
17
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
19
18
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
20
19
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -37,7 +36,6 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
37
36
|
/**
|
|
38
37
|
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
39
38
|
* never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
40
|
-
*
|
|
41
39
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
42
40
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
43
41
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -66,11 +64,9 @@ export type DefinedInitialDataInfiniteOptions<
|
|
|
66
64
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
67
65
|
*
|
|
68
66
|
* This overload is selected when `initialData` is set.
|
|
69
|
-
*
|
|
70
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
71
67
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
72
68
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
73
|
-
*
|
|
69
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
74
70
|
* @example
|
|
75
71
|
* ```tsx
|
|
76
72
|
* import { For } from 'solid-js'
|
|
@@ -133,11 +129,9 @@ export function infiniteQueryOptions<
|
|
|
133
129
|
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
134
130
|
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
135
131
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
136
|
-
*
|
|
137
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
138
132
|
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
139
133
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
140
|
-
*
|
|
134
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
141
135
|
* @example
|
|
142
136
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
143
137
|
* ```tsx
|
package/src/isRestoring.ts
CHANGED
|
@@ -7,7 +7,6 @@ const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
|
|
|
7
7
|
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` primitive alongside it to
|
|
8
8
|
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
9
9
|
* race conditions between the restore and mounting queries.
|
|
10
|
-
*
|
|
11
10
|
* @returns An accessor that reads `true` while a persisted client is being restored, `false` otherwise.
|
|
12
11
|
*/
|
|
13
12
|
export const useIsRestoring = () => useContext(IsRestoringContext)
|
package/src/mutationOptions.ts
CHANGED
|
@@ -5,12 +5,10 @@ import type { MutationOptions } from './types'
|
|
|
5
5
|
* You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
|
|
6
6
|
* `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
|
|
7
7
|
* `useMutationState`.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
10
8
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
|
|
11
9
|
* required `mutationKey`.
|
|
12
10
|
* @returns The same options object, unchanged.
|
|
13
|
-
*
|
|
11
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
14
12
|
* @example
|
|
15
13
|
* Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
|
|
16
14
|
* ```tsx
|
|
@@ -49,13 +47,11 @@ export function mutationOptions<
|
|
|
49
47
|
* `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
|
|
50
48
|
* `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
|
|
51
49
|
* such as `status`.
|
|
52
|
-
*
|
|
53
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
54
50
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
|
|
55
51
|
* `mutationKey`.
|
|
56
52
|
* @returns The same options object, unchanged.
|
|
57
53
|
* @remarks See the other overload's example for looking a mutation up via `useMutationState`.
|
|
58
|
-
*
|
|
54
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
59
55
|
* @example
|
|
60
56
|
* ```tsx
|
|
61
57
|
* import { mutationOptions, useMutation } from '@tanstack/solid-query'
|
package/src/queryOptions.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { Accessor } from 'solid-js'
|
|
|
11
11
|
* `undefined` while the query is `pending`. `queryOptions` itself accepts and returns a plain object (its
|
|
12
12
|
* parameter type is `ReturnType<UndefinedInitialDataOptions<...>>`, i.e. this `Accessor` called); Solid's
|
|
13
13
|
* reactivity applies where the result is consumed instead, e.g. `useQuery(() => options)`.
|
|
14
|
-
*
|
|
15
14
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
16
15
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
17
16
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -31,7 +30,6 @@ export type UndefinedInitialDataOptions<
|
|
|
31
30
|
/**
|
|
32
31
|
* The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
|
|
33
32
|
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
34
|
-
*
|
|
35
33
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
36
34
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
37
35
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -55,11 +53,9 @@ export type DefinedInitialDataOptions<
|
|
|
55
53
|
*
|
|
56
54
|
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
|
|
57
55
|
* a `select` changes `TData` to include `undefined`).
|
|
58
|
-
*
|
|
59
|
-
* @see {@link useQuery} to run a query with these options.
|
|
60
56
|
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
|
|
61
57
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
62
|
-
*
|
|
58
|
+
* @see {@link useQuery} to run a query with these options.
|
|
63
59
|
* @example
|
|
64
60
|
* ```tsx
|
|
65
61
|
* import { For } from 'solid-js'
|
|
@@ -105,11 +101,9 @@ export function queryOptions<
|
|
|
105
101
|
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
106
102
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
107
103
|
* is the query key to generate options for.
|
|
108
|
-
*
|
|
109
|
-
* @see {@link useQuery} to run a query with these options.
|
|
110
104
|
* @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
|
|
111
105
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
112
|
-
*
|
|
106
|
+
* @see {@link useQuery} to run a query with these options.
|
|
113
107
|
* @example
|
|
114
108
|
* A parameterized factory, so the same options object can be reused per `id`:
|
|
115
109
|
* ```tsx
|
package/src/types.ts
CHANGED
|
@@ -22,7 +22,6 @@ import type { Accessor } from 'solid-js'
|
|
|
22
22
|
/**
|
|
23
23
|
* The options accepted by `useQuery`. Extends {@link QueryObserverOptions} from `@tanstack/query-core` with
|
|
24
24
|
* the `solid-query`-specific `deferStream` and `suspense` options.
|
|
25
|
-
*
|
|
26
25
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
27
26
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
28
27
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -45,7 +44,6 @@ export interface UseBaseQueryOptions<
|
|
|
45
44
|
* Only applicable while rendering queries on the server with streaming.
|
|
46
45
|
* Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
|
|
47
46
|
* This can be useful to avoid sending a loading state to the client before the query has resolved.
|
|
48
|
-
*
|
|
49
47
|
* @defaultValue false
|
|
50
48
|
*/
|
|
51
49
|
deferStream?: boolean
|
|
@@ -59,7 +57,6 @@ export interface UseBaseQueryOptions<
|
|
|
59
57
|
|
|
60
58
|
/**
|
|
61
59
|
* The options accepted by `useQuery` and `queryOptions`.
|
|
62
|
-
*
|
|
63
60
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
64
61
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
65
62
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -82,7 +79,6 @@ export interface QueryOptions<
|
|
|
82
79
|
/**
|
|
83
80
|
* The accessor `useQuery` expects as its first argument — Solid re-evaluates it reactively, so `queryKey` and
|
|
84
81
|
* other options can depend on signals.
|
|
85
|
-
*
|
|
86
82
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
87
83
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
88
84
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -102,7 +98,6 @@ export type UseQueryOptions<
|
|
|
102
98
|
* The object `useQuery` returns when `initialData` isn't set — `data`/`error` may still be `undefined`/`null`
|
|
103
99
|
* while the query is `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`.
|
|
104
100
|
* `useInfiniteQuery` returns {@link UseInfiniteQueryResult} instead.
|
|
105
|
-
*
|
|
106
101
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
107
102
|
* @template TError - The type of errors this query may hold.
|
|
108
103
|
*/
|
|
@@ -114,7 +109,6 @@ export type UseBaseQueryResult<
|
|
|
114
109
|
/**
|
|
115
110
|
* The object `useQuery` returns — `data`/`error` may still be `undefined`/`null` while the query is
|
|
116
111
|
* `pending`.
|
|
117
|
-
*
|
|
118
112
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
119
113
|
* @template TError - The type of errors this query may hold.
|
|
120
114
|
*/
|
|
@@ -126,7 +120,6 @@ export type UseQueryResult<
|
|
|
126
120
|
/**
|
|
127
121
|
* The object `useQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
|
|
128
122
|
* `select` changes `TData` to include `undefined`).
|
|
129
|
-
*
|
|
130
123
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
131
124
|
* @template TError - The type of errors this query may hold.
|
|
132
125
|
*/
|
|
@@ -138,7 +131,6 @@ export type DefinedUseBaseQueryResult<
|
|
|
138
131
|
/**
|
|
139
132
|
* The object `useQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
|
|
140
133
|
* `select` changes `TData` to include `undefined`).
|
|
141
|
-
*
|
|
142
134
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
143
135
|
* @template TError - The type of errors this query may hold.
|
|
144
136
|
*/
|
|
@@ -150,7 +142,6 @@ export type DefinedUseQueryResult<
|
|
|
150
142
|
/* --- Create Infinite Queries Types --- */
|
|
151
143
|
/**
|
|
152
144
|
* The options accepted by `useInfiniteQuery`.
|
|
153
|
-
*
|
|
154
145
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
155
146
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
156
147
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -186,7 +177,6 @@ export interface InfiniteQueryOptions<
|
|
|
186
177
|
* Only applicable while rendering queries on the server with streaming.
|
|
187
178
|
* Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
|
|
188
179
|
* This can be useful to avoid sending a loading state to the client before the query has resolved.
|
|
189
|
-
*
|
|
190
180
|
* @defaultValue false
|
|
191
181
|
*/
|
|
192
182
|
deferStream?: boolean
|
|
@@ -201,7 +191,6 @@ export interface InfiniteQueryOptions<
|
|
|
201
191
|
/**
|
|
202
192
|
* The accessor `useInfiniteQuery` expects as its first argument — Solid re-evaluates it reactively, so
|
|
203
193
|
* `queryKey` and other options can depend on signals.
|
|
204
|
-
*
|
|
205
194
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
206
195
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
207
196
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -221,7 +210,6 @@ export type UseInfiniteQueryOptions<
|
|
|
221
210
|
/**
|
|
222
211
|
* The object `useInfiniteQuery` returns — `data`/`error` may still be `undefined`/`null` while the query is
|
|
223
212
|
* `pending`.
|
|
224
|
-
*
|
|
225
213
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
226
214
|
* @template TError - The type of errors this query may hold.
|
|
227
215
|
*/
|
|
@@ -233,7 +221,6 @@ export type UseInfiniteQueryResult<
|
|
|
233
221
|
/**
|
|
234
222
|
* The object `useInfiniteQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
|
|
235
223
|
* `select` changes `TData` to include `undefined`).
|
|
236
|
-
*
|
|
237
224
|
* @template TData - The type `data` ends up as, after `select` runs (if set).
|
|
238
225
|
* @template TError - The type of errors this query may hold.
|
|
239
226
|
*/
|
|
@@ -245,7 +232,6 @@ export type DefinedUseInfiniteQueryResult<
|
|
|
245
232
|
/* --- Create Mutation Types --- */
|
|
246
233
|
/**
|
|
247
234
|
* The options accepted by `useMutation` and `mutationOptions`.
|
|
248
|
-
*
|
|
249
235
|
* @template TData - The type your `mutationFn` resolves to.
|
|
250
236
|
* @template TError - The type of errors your `mutationFn` may throw.
|
|
251
237
|
* @template TVariables - The type of the variables your `mutationFn` accepts.
|
|
@@ -264,7 +250,6 @@ export interface MutationOptions<
|
|
|
264
250
|
/**
|
|
265
251
|
* The accessor `useMutation` expects as its first argument — Solid re-evaluates it reactively, so callbacks
|
|
266
252
|
* and other options can depend on signals.
|
|
267
|
-
*
|
|
268
253
|
* @template TData - The type your `mutationFn` resolves to.
|
|
269
254
|
* @template TError - The type of errors your `mutationFn` may throw.
|
|
270
255
|
* @template TVariables - The type of the variables your `mutationFn` accepts.
|
|
@@ -277,6 +262,17 @@ export type UseMutationOptions<
|
|
|
277
262
|
TOnMutateResult = unknown,
|
|
278
263
|
> = Accessor<MutationOptions<TData, TError, TVariables, TOnMutateResult>>
|
|
279
264
|
|
|
265
|
+
/**
|
|
266
|
+
* The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
|
|
267
|
+
* `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
|
|
268
|
+
* through the mutation result instead of being thrown by `mutate`, unless `throwOnError` makes `useMutation`
|
|
269
|
+
* rethrow them.
|
|
270
|
+
* @template TData - The type your mutation function resolves to.
|
|
271
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
272
|
+
* @template TVariables - The type of the variable passed to `mutate`.
|
|
273
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
274
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
275
|
+
*/
|
|
280
276
|
export type UseMutateFunction<
|
|
281
277
|
TData = unknown,
|
|
282
278
|
TError = DefaultError,
|
|
@@ -291,7 +287,6 @@ export type UseMutateFunction<
|
|
|
291
287
|
/**
|
|
292
288
|
* The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
|
|
293
289
|
* promise which can be awaited.
|
|
294
|
-
*
|
|
295
290
|
* @template TData - The type your `mutationFn` resolves to.
|
|
296
291
|
* @template TError - The type of errors your `mutationFn` may throw.
|
|
297
292
|
* @template TVariables - The type of the variable passed to `mutateAsync`.
|
|
@@ -308,7 +303,6 @@ export type UseMutateAsyncFunction<
|
|
|
308
303
|
/**
|
|
309
304
|
* The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
|
|
310
305
|
* `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
|
|
311
|
-
*
|
|
312
306
|
* @template TData - The type your `mutationFn` resolves to.
|
|
313
307
|
* @template TError - The type of errors your `mutationFn` may throw.
|
|
314
308
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -337,7 +331,6 @@ export type UseBaseMutationResult<
|
|
|
337
331
|
|
|
338
332
|
/**
|
|
339
333
|
* The result of `useMutation`. Same as {@link UseBaseMutationResult}.
|
|
340
|
-
*
|
|
341
334
|
* @template TData - The type your `mutationFn` resolves to.
|
|
342
335
|
* @template TError - The type of errors your `mutationFn` may throw.
|
|
343
336
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -24,11 +24,22 @@ import type {
|
|
|
24
24
|
QueryObserverResult,
|
|
25
25
|
} from '@tanstack/query-core'
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Applies the `reconcile` option when writing a new observer result into the store.
|
|
29
|
+
* @param store - The current result in the store.
|
|
30
|
+
* @param result - The new observer result.
|
|
31
|
+
* @param reconcileOption - `false` to replace the data, a function that merges the old and new
|
|
32
|
+
* data, or the key used by Solid's `reconcile` to match array items.
|
|
33
|
+
* @param queryHash - The query hash, used in the warning if the data can't be cloned.
|
|
34
|
+
* @returns The result to store, with its data reconciled.
|
|
35
|
+
*/
|
|
27
36
|
function reconcileFn<TData, TError>(
|
|
28
37
|
store: QueryObserverResult<TData, TError>,
|
|
29
38
|
result: QueryObserverResult<TData, TError>,
|
|
30
39
|
reconcileOption:
|
|
31
|
-
|
|
40
|
+
| string
|
|
41
|
+
| false
|
|
42
|
+
| ((oldData: TData | undefined, newData: TData) => TData),
|
|
32
43
|
queryHash?: string,
|
|
33
44
|
): QueryObserverResult<TData, TError> {
|
|
34
45
|
if (reconcileOption === false) return result
|
|
@@ -60,6 +71,10 @@ function reconcileFn<TData, TError>(
|
|
|
60
71
|
/**
|
|
61
72
|
* Solid's `onHydrated` functionality will silently "fail" (hydrate with an empty object)
|
|
62
73
|
* if the resource data is not serializable.
|
|
74
|
+
* @param query - The query the result belongs to.
|
|
75
|
+
* @param result - The observer result to make serializable.
|
|
76
|
+
* @returns On the server, a copy of the result without its functions and with the query's
|
|
77
|
+
* dehydrated state attached as `hydrationData`. On the client, the result as is.
|
|
63
78
|
*/
|
|
64
79
|
const hydratableObserverResult = <
|
|
65
80
|
TQueryFnData,
|
|
@@ -97,7 +112,15 @@ const hydratableObserverResult = <
|
|
|
97
112
|
return obj
|
|
98
113
|
}
|
|
99
114
|
|
|
100
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Base Query Function that is used to create the query.
|
|
117
|
+
* @param options - A function that returns the query options.
|
|
118
|
+
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
119
|
+
* `InfiniteQueryObserver`).
|
|
120
|
+
* @param queryClient - A function that returns a custom `QueryClient`. Otherwise, the one from the
|
|
121
|
+
* nearest context is used.
|
|
122
|
+
* @returns The reactive query result.
|
|
123
|
+
*/
|
|
101
124
|
export function useBaseQuery<
|
|
102
125
|
TQueryFnData,
|
|
103
126
|
TError,
|
|
@@ -185,6 +208,10 @@ export function useBaseQuery<
|
|
|
185
208
|
})
|
|
186
209
|
}
|
|
187
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Writes an observer result into the store, applying the query's `reconcile` option.
|
|
213
|
+
* @param res - The observer result to write.
|
|
214
|
+
*/
|
|
188
215
|
function setStateWithReconciliation(res: typeof observerResult) {
|
|
189
216
|
const opts = observer().options
|
|
190
217
|
// @ts-expect-error - Reconcile option is not correctly typed internally
|
|
@@ -200,6 +227,11 @@ export function useBaseQuery<
|
|
|
200
227
|
})
|
|
201
228
|
}
|
|
202
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Creates the signal used as the resource's storage, backed by the query store. Hydration data is
|
|
232
|
+
* removed from values written to it.
|
|
233
|
+
* @returns A getter and setter for the store.
|
|
234
|
+
*/
|
|
203
235
|
function createDeepSignal<T>(): Signal<T> {
|
|
204
236
|
return [
|
|
205
237
|
() => state,
|
|
@@ -280,6 +312,8 @@ export function useBaseQuery<
|
|
|
280
312
|
* Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.
|
|
281
313
|
*
|
|
282
314
|
* Note that this is only invoked on the client, for queries that were originally run on the server.
|
|
315
|
+
* @param _k - The resource source, unused.
|
|
316
|
+
* @param info - The hydrated resource value, which carries the query's `hydrationData`.
|
|
283
317
|
*/
|
|
284
318
|
onHydrated(_k, info) {
|
|
285
319
|
if (info.value && 'hydrationData' in info.value) {
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -24,11 +24,6 @@ import type {
|
|
|
24
24
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
25
25
|
*
|
|
26
26
|
* This overload is selected when `initialData` is set.
|
|
27
|
-
*
|
|
28
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
29
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
30
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
31
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
32
27
|
* @param options - An accessor returning the {@link DefinedInitialDataInfiniteOptions} to use — everything you
|
|
33
28
|
* can pass to `useInfiniteQuery`, with `initialData` set.
|
|
34
29
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
@@ -37,7 +32,10 @@ import type {
|
|
|
37
32
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
38
33
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
39
34
|
* `InfiniteData<TQueryFnData>` shape.
|
|
40
|
-
*
|
|
35
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
36
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
37
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
38
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
41
39
|
* @example
|
|
42
40
|
* ```tsx
|
|
43
41
|
* import { For } from 'solid-js'
|
|
@@ -87,11 +85,6 @@ export function useInfiniteQuery<
|
|
|
87
85
|
/**
|
|
88
86
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
89
87
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
90
|
-
*
|
|
91
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
92
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
93
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
94
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
95
88
|
* @param options - An accessor returning the {@link UndefinedInitialDataInfiniteOptions} to use — everything
|
|
96
89
|
* you can pass to `useInfiniteQuery`.
|
|
97
90
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
@@ -100,7 +93,10 @@ export function useInfiniteQuery<
|
|
|
100
93
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
101
94
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
102
95
|
* `InfiniteData<TQueryFnData>` shape.
|
|
103
|
-
*
|
|
96
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
97
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
98
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
99
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
104
100
|
* @example
|
|
105
101
|
* Fetching the next page from a "Load More" button click:
|
|
106
102
|
* ```tsx
|
|
@@ -140,7 +136,6 @@ export function useInfiniteQuery<
|
|
|
140
136
|
* )
|
|
141
137
|
* }
|
|
142
138
|
* ```
|
|
143
|
-
*
|
|
144
139
|
* @example
|
|
145
140
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
146
141
|
* sentinel element after the list:
|
package/src/useIsFetching.ts
CHANGED
|
@@ -7,13 +7,11 @@ import type { Accessor } from 'solid-js'
|
|
|
7
7
|
/**
|
|
8
8
|
* The `useIsFetching` primitive returns the `number` of the queries that your application is loading or fetching
|
|
9
9
|
* in the background (useful for app-wide loading indicators).
|
|
10
|
-
*
|
|
11
10
|
* @param filters - An accessor returning the {@link QueryFilters} to narrow down the matched queries.
|
|
12
11
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
13
12
|
* will be used.
|
|
14
13
|
* @returns An accessor for the `number` of the queries that your application is currently loading or fetching
|
|
15
14
|
* in the background.
|
|
16
|
-
*
|
|
17
15
|
* @example
|
|
18
16
|
* ```tsx
|
|
19
17
|
* import { useIsFetching } from '@tanstack/solid-query'
|
package/src/useIsMutating.ts
CHANGED
|
@@ -7,12 +7,10 @@ import type { Accessor } from 'solid-js'
|
|
|
7
7
|
/**
|
|
8
8
|
* The `useIsMutating` primitive returns the `number` of mutations that your application currently has `pending`
|
|
9
9
|
* (useful for app-wide loading indicators).
|
|
10
|
-
*
|
|
11
10
|
* @param filters - An accessor returning the {@link MutationFilters} to narrow down the matched mutations.
|
|
12
11
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
13
12
|
* will be used.
|
|
14
13
|
* @returns An accessor for the `number` of the mutations that your application currently has `pending`.
|
|
15
|
-
*
|
|
16
14
|
* @example
|
|
17
15
|
* ```tsx
|
|
18
16
|
* import { useIsMutating } from '@tanstack/solid-query'
|
package/src/useMutation.ts
CHANGED
|
@@ -14,7 +14,6 @@ import type { Accessor } from 'solid-js'
|
|
|
14
14
|
/**
|
|
15
15
|
* Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
|
|
16
16
|
* `useMutation` is the primitive for that.
|
|
17
|
-
*
|
|
18
17
|
* @param options - An accessor returning the {@link UseMutationOptions} to use.
|
|
19
18
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
20
19
|
* will be used.
|
|
@@ -23,7 +22,6 @@ import type { Accessor } from 'solid-js'
|
|
|
23
22
|
* mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
|
|
24
23
|
* fire only for the latest call you've made, and only while the component is still mounted — unmounting before
|
|
25
24
|
* the mutation settles removes the subscription and prevents them from firing.
|
|
26
|
-
*
|
|
27
25
|
* @example
|
|
28
26
|
* ```tsx
|
|
29
27
|
* import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
|
@@ -45,7 +43,6 @@ import type { Accessor } from 'solid-js'
|
|
|
45
43
|
* )
|
|
46
44
|
* }
|
|
47
45
|
* ```
|
|
48
|
-
*
|
|
49
46
|
* @example
|
|
50
47
|
* Rendering the mutation's own state, rather than just firing it off:
|
|
51
48
|
* ```tsx
|
|
@@ -71,7 +68,6 @@ import type { Accessor } from 'solid-js'
|
|
|
71
68
|
* )
|
|
72
69
|
* }
|
|
73
70
|
* ```
|
|
74
|
-
*
|
|
75
71
|
* @example
|
|
76
72
|
* Optimistic update via `onMutate`, rolling back on `onError`:
|
|
77
73
|
* ```tsx
|
|
@@ -107,7 +103,6 @@ import type { Accessor } from 'solid-js'
|
|
|
107
103
|
* )
|
|
108
104
|
* }
|
|
109
105
|
* ```
|
|
110
|
-
*
|
|
111
106
|
* @example
|
|
112
107
|
* Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
|
113
108
|
* promise per call instead, so you can wait for all of them when they succeed:
|
|
@@ -137,7 +132,6 @@ import type { Accessor } from 'solid-js'
|
|
|
137
132
|
* )
|
|
138
133
|
* }
|
|
139
134
|
* ```
|
|
140
|
-
*
|
|
141
135
|
* @example
|
|
142
136
|
* If some of the mutations above can fail independently of the others, and you want to know which ones
|
|
143
137
|
* did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
package/src/useMutationState.ts
CHANGED
|
@@ -30,6 +30,13 @@ type MutationStateOptions<
|
|
|
30
30
|
select?: (mutation: TMutation) => TResult
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
|
|
35
|
+
* (or to their state, by default).
|
|
36
|
+
* @param mutationCache - The mutation cache to read.
|
|
37
|
+
* @param options - The `filters` to match and the `select` function to map each mutation with.
|
|
38
|
+
* @returns The selected value of every matching mutation.
|
|
39
|
+
*/
|
|
33
40
|
function getResult<
|
|
34
41
|
TResult = MutationState,
|
|
35
42
|
TMutation extends Mutation<any, any, any, any> =
|
|
@@ -52,13 +59,11 @@ function getResult<
|
|
|
52
59
|
* `useMutationState` is a primitive that gives you access to all mutations in the `MutationCache`. You can pass
|
|
53
60
|
* `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
|
|
54
61
|
* state.
|
|
55
|
-
*
|
|
56
62
|
* @param options - An accessor returning the `filters` to narrow down matched mutations, and an optional
|
|
57
63
|
* `select` to transform the mutation state.
|
|
58
64
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
59
65
|
* will be used.
|
|
60
66
|
* @returns An accessor for an array of whatever `select` returns for each matching mutation.
|
|
61
|
-
*
|
|
62
67
|
* @example
|
|
63
68
|
* Get all variables of all running mutations:
|
|
64
69
|
* ```tsx
|
|
@@ -73,7 +78,6 @@ function getResult<
|
|
|
73
78
|
* return <>{pendingVariables().length} posts saving...</>
|
|
74
79
|
* }
|
|
75
80
|
* ```
|
|
76
|
-
*
|
|
77
81
|
* @example
|
|
78
82
|
* Get all data for specific mutations via the `mutationKey`:
|
|
79
83
|
* ```tsx
|
|
@@ -101,7 +105,6 @@ function getResult<
|
|
|
101
105
|
* )
|
|
102
106
|
* }
|
|
103
107
|
* ```
|
|
104
|
-
*
|
|
105
108
|
* @example
|
|
106
109
|
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
107
110
|
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
package/src/useQueries.ts
CHANGED
|
@@ -206,7 +206,6 @@ type QueriesResults<
|
|
|
206
206
|
* will be used.
|
|
207
207
|
* @returns The combined result. Without `combine`, this is an array with all the query results, in the same
|
|
208
208
|
* order as the input. When `combine` is provided, this is the value returned by `combine` instead.
|
|
209
|
-
*
|
|
210
209
|
* @example
|
|
211
210
|
* ```tsx
|
|
212
211
|
* import { For } from 'solid-js'
|
|
@@ -234,7 +233,6 @@ type QueriesResults<
|
|
|
234
233
|
* )
|
|
235
234
|
* }
|
|
236
235
|
* ```
|
|
237
|
-
*
|
|
238
236
|
* @example
|
|
239
237
|
* Combining results into a single value:
|
|
240
238
|
* ```tsx
|