@tanstack/solid-query 5.102.8 → 5.103.0

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.
@@ -8,6 +8,20 @@ import type {
8
8
  import type { InfiniteQueryOptions } from './types'
9
9
  import type { Accessor } from 'solid-js'
10
10
 
11
+ /**
12
+ * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
13
+ * may be `undefined` while the query is `pending`. `infiniteQueryOptions` itself accepts and returns a plain
14
+ * object (its parameter type is `ReturnType<UndefinedInitialDataInfiniteOptions<...>>`, i.e. this `Accessor`
15
+ * called); Solid's reactivity applies where the result is consumed instead, e.g.
16
+ * `useInfiniteQuery(() => options)`.
17
+ *
18
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
19
+ * @template TError - The type of errors your `queryFn` may throw.
20
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
21
+ * the shape of all fetched pages plus their page params.
22
+ * @template TQueryKey - The type of your `queryKey`.
23
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
24
+ */
11
25
  export type UndefinedInitialDataInfiniteOptions<
12
26
  TQueryFnData,
13
27
  TError = DefaultError,
@@ -20,6 +34,17 @@ export type UndefinedInitialDataInfiniteOptions<
20
34
  }
21
35
  >
22
36
 
37
+ /**
38
+ * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
39
+ * never `undefined`.
40
+ *
41
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
42
+ * @template TError - The type of errors your `queryFn` may throw.
43
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
44
+ * the shape of all fetched pages plus their page params.
45
+ * @template TQueryKey - The type of your `queryKey`.
46
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
47
+ */
23
48
  export type DefinedInitialDataInfiniteOptions<
24
49
  TQueryFnData,
25
50
  TError = DefaultError,
@@ -34,6 +59,49 @@ export type DefinedInitialDataInfiniteOptions<
34
59
  | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
35
60
  }
36
61
  >
62
+
63
+ /**
64
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
65
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
66
+ * `options.queryKey` is required and is the query key to generate options for.
67
+ *
68
+ * This overload is selected when `initialData` is set.
69
+ *
70
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
71
+ * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
72
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * import { For } from 'solid-js'
77
+ * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/solid-query'
78
+ *
79
+ * const projectsOptions = infiniteQueryOptions({
80
+ * queryKey: ['projects'],
81
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
82
+ * initialPageParam: 0,
83
+ * getNextPageParam: (lastPage) => lastPage.nextId,
84
+ * initialData: { pages: [], pageParams: [] },
85
+ * })
86
+ *
87
+ * function Projects() {
88
+ * // `projectsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
89
+ * // list stays visible alongside the error.
90
+ * const projectsQuery = useInfiniteQuery(() => projectsOptions)
91
+ *
92
+ * return (
93
+ * <div>
94
+ * {projectsQuery.isError ? <span>Error: {projectsQuery.error.message}</span> : null}
95
+ * <ul>
96
+ * <For each={projectsQuery.data.pages}>
97
+ * {(page) => <For each={page.projects}>{(p) => <li>{p.name}</li>}</For>}
98
+ * </For>
99
+ * </ul>
100
+ * </div>
101
+ * )
102
+ * }
103
+ * ```
104
+ */
37
105
  export function infiniteQueryOptions<
38
106
  TQueryFnData,
39
107
  TError = DefaultError,
@@ -60,6 +128,49 @@ export function infiniteQueryOptions<
60
128
  >
61
129
  > &
62
130
  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
131
+
132
+ /**
133
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
134
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
135
+ * `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
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
139
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
140
+ *
141
+ * @example
142
+ * A parameterized factory, so the same options object can be reused per `postId`:
143
+ * ```tsx
144
+ * import { For, Match, Switch } from 'solid-js'
145
+ * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/solid-query'
146
+ *
147
+ * const commentsOptions = (postId: string) =>
148
+ * infiniteQueryOptions({
149
+ * queryKey: ['post', postId, 'comments'],
150
+ * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
151
+ * initialPageParam: 0,
152
+ * getNextPageParam: (lastPage) => lastPage.nextId,
153
+ * })
154
+ *
155
+ * function Comments(props: { postId: string }) {
156
+ * const commentsQuery = useInfiniteQuery(() => commentsOptions(props.postId))
157
+ *
158
+ * return (
159
+ * <Switch>
160
+ * <Match when={commentsQuery.isPending}>Loading...</Match>
161
+ * <Match when={commentsQuery.isError}>Error: {commentsQuery.error.message}</Match>
162
+ * <Match when={commentsQuery.isSuccess}>
163
+ * <ul>
164
+ * <For each={commentsQuery.data.pages}>
165
+ * {(page) => <For each={page.comments}>{(c) => <li>{c.text}</li>}</For>}
166
+ * </For>
167
+ * </ul>
168
+ * </Match>
169
+ * </Switch>
170
+ * )
171
+ * }
172
+ * ```
173
+ */
63
174
  export function infiniteQueryOptions<
64
175
  TQueryFnData,
65
176
  TError = DefaultError,
@@ -3,5 +3,17 @@ import type { Accessor } from 'solid-js'
3
3
 
4
4
  const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
5
5
 
6
+ /**
7
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
8
+ * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9
+ * race conditions between the restore and mounting queries.
10
+ *
11
+ * @returns An accessor that reads `true` while a persisted client is being restored, `false` otherwise.
12
+ */
6
13
  export const useIsRestoring = () => useContext(IsRestoringContext)
14
+
15
+ /**
16
+ * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
17
+ * being restored, read by `useIsRestoring`.
18
+ */
7
19
  export const IsRestoringProvider = IsRestoringContext.Provider
@@ -1,6 +1,35 @@
1
1
  import type { DefaultError, WithRequired } from '@tanstack/query-core'
2
2
  import type { MutationOptions } from './types'
3
3
 
4
+ /**
5
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
6
+ * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
7
+ * `useMutationState`.
8
+ *
9
+ * @see {@link useMutation} to run the mutation these options describe.
10
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
11
+ * required `mutationKey`.
12
+ * @returns The same options object, unchanged.
13
+ *
14
+ * @example
15
+ * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
16
+ * ```tsx
17
+ * import { mutationOptions, useMutationState } from '@tanstack/solid-query'
18
+ *
19
+ * const createPostOptions = mutationOptions({
20
+ * mutationKey: ['posts', 'create'],
21
+ * mutationFn: createPost,
22
+ * })
23
+ *
24
+ * function SavingIndicator() {
25
+ * const isCreatingPost = useMutationState(() => ({
26
+ * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
27
+ * }))
28
+ *
29
+ * return isCreatingPost().length > 0 ? <span>Saving…</span> : null
30
+ * }
31
+ * ```
32
+ */
4
33
  export function mutationOptions<
5
34
  TData = unknown,
6
35
  TError = DefaultError,
@@ -15,6 +44,32 @@ export function mutationOptions<
15
44
  MutationOptions<TData, TError, TVariables, TOnMutateResult>,
16
45
  'mutationKey'
17
46
  >
47
+ /**
48
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No
49
+ * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
50
+ * `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
51
+ * such as `status`.
52
+ *
53
+ * @see {@link useMutation} to run the mutation these options describe.
54
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
55
+ * `mutationKey`.
56
+ * @returns The same options object, unchanged.
57
+ * @remarks See the other overload's example for looking a mutation up via `useMutationState`.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * import { mutationOptions, useMutation } from '@tanstack/solid-query'
62
+ *
63
+ * const createPostOptions = mutationOptions({
64
+ * mutationFn: createPost,
65
+ * })
66
+ *
67
+ * function CreatePost() {
68
+ * const createPostMutation = useMutation(() => createPostOptions)
69
+ * return <button onClick={() => createPostMutation.mutate({ title: 'Hello' })}>Create</button>
70
+ * }
71
+ * ```
72
+ */
18
73
  export function mutationOptions<
19
74
  TData = unknown,
20
75
  TError = DefaultError,
@@ -6,6 +6,17 @@ import type {
6
6
  import type { QueryOptions } from './types'
7
7
  import type { Accessor } from 'solid-js'
8
8
 
9
+ /**
10
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
11
+ * `undefined` while the query is `pending`. `queryOptions` itself accepts and returns a plain object (its
12
+ * parameter type is `ReturnType<UndefinedInitialDataOptions<...>>`, i.e. this `Accessor` called); Solid's
13
+ * reactivity applies where the result is consumed instead, e.g. `useQuery(() => options)`.
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 TQueryKey - The type of your `queryKey`.
19
+ */
9
20
  export type UndefinedInitialDataOptions<
10
21
  TQueryFnData = unknown,
11
22
  TError = DefaultError,
@@ -17,6 +28,15 @@ export type UndefinedInitialDataOptions<
17
28
  }
18
29
  >
19
30
 
31
+ /**
32
+ * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
33
+ * `undefined`.
34
+ *
35
+ * @template TQueryFnData - The type your `queryFn` resolves to.
36
+ * @template TError - The type of errors your `queryFn` may throw.
37
+ * @template TData - The type `data` ends up as after `select` runs.
38
+ * @template TQueryKey - The type of your `queryKey`.
39
+ */
20
40
  export type DefinedInitialDataOptions<
21
41
  TQueryFnData = unknown,
22
42
  TError = DefaultError,
@@ -28,6 +48,44 @@ export type DefinedInitialDataOptions<
28
48
  }
29
49
  >
30
50
 
51
+ /**
52
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
53
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
54
+ * is the query key to generate options for.
55
+ *
56
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
57
+ *
58
+ * @see {@link useQuery} to run a query with these options.
59
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
60
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * import { For } from 'solid-js'
65
+ * import { queryOptions, useQuery } from '@tanstack/solid-query'
66
+ *
67
+ * const postsOptions = queryOptions({
68
+ * queryKey: ['posts'],
69
+ * queryFn: fetchPosts,
70
+ * initialData: [],
71
+ * })
72
+ *
73
+ * function Posts() {
74
+ * // `postsQuery.data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,
75
+ * // so the list stays visible alongside the error.
76
+ * const postsQuery = useQuery(() => postsOptions)
77
+ *
78
+ * return (
79
+ * <div>
80
+ * {postsQuery.isError ? <span>Error: {postsQuery.error.message}</span> : null}
81
+ * <ul>
82
+ * <For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
83
+ * </ul>
84
+ * </div>
85
+ * )
86
+ * }
87
+ * ```
88
+ */
31
89
  export function queryOptions<
32
90
  TQueryFnData = unknown,
33
91
  TError = DefaultError,
@@ -35,13 +93,49 @@ export function queryOptions<
35
93
  TQueryKey extends QueryKey = QueryKey,
36
94
  >(
37
95
  options: ReturnType<
38
- UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
96
+ DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
39
97
  >,
40
98
  ): ReturnType<
41
- UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
99
+ DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
42
100
  > &
43
101
  QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
44
102
 
103
+ /**
104
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
105
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
106
+ * is the query key to generate options for.
107
+ *
108
+ * @see {@link useQuery} to run a query with these options.
109
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
110
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
111
+ *
112
+ * @example
113
+ * A parameterized factory, so the same options object can be reused per `id`:
114
+ * ```tsx
115
+ * import { Match, Switch } from 'solid-js'
116
+ * import { queryOptions, useQuery } from '@tanstack/solid-query'
117
+ *
118
+ * const postOptions = (id: string) =>
119
+ * queryOptions({
120
+ * queryKey: ['post', id],
121
+ * queryFn: () => fetchPost(id),
122
+ * })
123
+ *
124
+ * function Post(props: { id: string }) {
125
+ * const postQuery = useQuery(() => postOptions(props.id))
126
+ *
127
+ * return (
128
+ * <Switch>
129
+ * <Match when={postQuery.isPending}>Loading...</Match>
130
+ * <Match when={postQuery.isError}>Error: {postQuery.error.message}</Match>
131
+ * <Match when={postQuery.isSuccess}>
132
+ * <h1>{postQuery.data.title}</h1>
133
+ * </Match>
134
+ * </Switch>
135
+ * )
136
+ * }
137
+ * ```
138
+ */
45
139
  export function queryOptions<
46
140
  TQueryFnData = unknown,
47
141
  TError = DefaultError,
@@ -49,10 +143,10 @@ export function queryOptions<
49
143
  TQueryKey extends QueryKey = QueryKey,
50
144
  >(
51
145
  options: ReturnType<
52
- DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
146
+ UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
53
147
  >,
54
148
  ): ReturnType<
55
- DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
149
+ UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
56
150
  > &
57
151
  QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
58
152
 
package/src/types.ts CHANGED
@@ -19,6 +19,18 @@ import type {
19
19
  } from './QueryClient'
20
20
  import type { Accessor } from 'solid-js'
21
21
 
22
+ /**
23
+ * The options accepted by `useQuery`. Extends {@link QueryObserverOptions} from `@tanstack/query-core` with
24
+ * the `solid-query`-specific `deferStream` and `suspense` options.
25
+ *
26
+ * @template TQueryFnData - The type your `queryFn` resolves to.
27
+ * @template TError - The type of errors your `queryFn` may throw.
28
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
29
+ * `select` is used.
30
+ * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and
31
+ * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
32
+ * @template TQueryKey - The type of your `queryKey`.
33
+ */
22
34
  export interface UseBaseQueryOptions<
23
35
  TQueryFnData = unknown,
24
36
  TError = DefaultError,
@@ -44,6 +56,15 @@ export interface UseBaseQueryOptions<
44
56
  suspense?: boolean
45
57
  }
46
58
 
59
+ /**
60
+ * The options accepted by `useQuery` and `queryOptions`.
61
+ *
62
+ * @template TQueryFnData - The type your `queryFn` resolves to.
63
+ * @template TError - The type of errors your `queryFn` may throw.
64
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
65
+ * `select` is used.
66
+ * @template TQueryKey - The type of your `queryKey`.
67
+ */
47
68
  export interface QueryOptions<
48
69
  TQueryFnData = unknown,
49
70
  TError = DefaultError,
@@ -57,6 +78,16 @@ export interface QueryOptions<
57
78
  TQueryKey
58
79
  > {}
59
80
 
81
+ /**
82
+ * The accessor `useQuery` expects as its first argument — Solid re-evaluates it reactively, so `queryKey` and
83
+ * other options can depend on signals.
84
+ *
85
+ * @template TQueryFnData - The type your `queryFn` resolves to.
86
+ * @template TError - The type of errors your `queryFn` may throw.
87
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
88
+ * `select` is used.
89
+ * @template TQueryKey - The type of your `queryKey`.
90
+ */
60
91
  export type UseQueryOptions<
61
92
  TQueryFnData = unknown,
62
93
  TError = DefaultError,
@@ -66,27 +97,63 @@ export type UseQueryOptions<
66
97
 
67
98
  /* --- Create Query and Create Base Query Types --- */
68
99
 
100
+ /**
101
+ * The object `useQuery` returns when `initialData` isn't set — `data`/`error` may still be `undefined`/`null`
102
+ * while the query is `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`.
103
+ * `useInfiniteQuery` returns {@link UseInfiniteQueryResult} instead.
104
+ *
105
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
106
+ * @template TError - The type of errors this query may hold.
107
+ */
69
108
  export type UseBaseQueryResult<
70
109
  TData = unknown,
71
110
  TError = DefaultError,
72
111
  > = QueryObserverResult<TData, TError>
73
112
 
113
+ /**
114
+ * The object `useQuery` returns — `data`/`error` may still be `undefined`/`null` while the query is
115
+ * `pending`.
116
+ *
117
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
118
+ * @template TError - The type of errors this query may hold.
119
+ */
74
120
  export type UseQueryResult<
75
121
  TData = unknown,
76
122
  TError = DefaultError,
77
123
  > = UseBaseQueryResult<TData, TError>
78
124
 
125
+ /**
126
+ * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined`.
127
+ *
128
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
129
+ * @template TError - The type of errors this query may hold.
130
+ */
79
131
  export type DefinedUseBaseQueryResult<
80
132
  TData = unknown,
81
133
  TError = DefaultError,
82
134
  > = DefinedQueryObserverResult<TData, TError>
83
135
 
136
+ /**
137
+ * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined`.
138
+ *
139
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
140
+ * @template TError - The type of errors this query may hold.
141
+ */
84
142
  export type DefinedUseQueryResult<
85
143
  TData = unknown,
86
144
  TError = DefaultError,
87
145
  > = DefinedUseBaseQueryResult<TData, TError>
88
146
 
89
147
  /* --- Create Infinite Queries Types --- */
148
+ /**
149
+ * The options accepted by `useInfiniteQuery`.
150
+ *
151
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
152
+ * @template TError - The type of errors your `queryFn` may throw.
153
+ * @template TData - The type `data` ends up as after `select` runs.
154
+ * @template TQueryKey - The type of your `queryKey`.
155
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
156
+ */
90
157
  export interface InfiniteQueryOptions<
91
158
  TQueryFnData = unknown,
92
159
  TError = DefaultError,
@@ -119,6 +186,16 @@ export interface InfiniteQueryOptions<
119
186
  suspense?: boolean
120
187
  }
121
188
 
189
+ /**
190
+ * The accessor `useInfiniteQuery` expects as its first argument — Solid re-evaluates it reactively, so
191
+ * `queryKey` and other options can depend on signals.
192
+ *
193
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
194
+ * @template TError - The type of errors your `queryFn` may throw.
195
+ * @template TData - The type `data` ends up as after `select` runs.
196
+ * @template TQueryKey - The type of your `queryKey`.
197
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
198
+ */
122
199
  export type UseInfiniteQueryOptions<
123
200
  TQueryFnData = unknown,
124
201
  TError = DefaultError,
@@ -129,17 +206,38 @@ export type UseInfiniteQueryOptions<
129
206
  InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>
130
207
  >
131
208
 
209
+ /**
210
+ * The object `useInfiniteQuery` returns — `data`/`error` may still be `undefined`/`null` while the query is
211
+ * `pending`.
212
+ *
213
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
214
+ * @template TError - The type of errors this query may hold.
215
+ */
132
216
  export type UseInfiniteQueryResult<
133
217
  TData = unknown,
134
218
  TError = DefaultError,
135
219
  > = InfiniteQueryObserverResult<TData, TError>
136
220
 
221
+ /**
222
+ * The object `useInfiniteQuery` returns when `initialData` guarantees `data` is never `undefined`.
223
+ *
224
+ * @template TData - The type `data` ends up as, after `select` runs (if set).
225
+ * @template TError - The type of errors this query may hold.
226
+ */
137
227
  export type DefinedUseInfiniteQueryResult<
138
228
  TData = unknown,
139
229
  TError = DefaultError,
140
230
  > = DefinedInfiniteQueryObserverResult<TData, TError>
141
231
 
142
232
  /* --- Create Mutation Types --- */
233
+ /**
234
+ * The options accepted by `useMutation` and `mutationOptions`.
235
+ *
236
+ * @template TData - The type your `mutationFn` resolves to.
237
+ * @template TError - The type of errors your `mutationFn` may throw.
238
+ * @template TVariables - The type of the variables your `mutationFn` accepts.
239
+ * @template TOnMutateResult - The type returned by `onMutate`, passed on to `onSuccess`/`onError`/`onSettled`.
240
+ */
143
241
  export interface MutationOptions<
144
242
  TData = unknown,
145
243
  TError = DefaultError,
@@ -150,6 +248,15 @@ export interface MutationOptions<
150
248
  '_defaulted'
151
249
  > {}
152
250
 
251
+ /**
252
+ * The accessor `useMutation` expects as its first argument — Solid re-evaluates it reactively, so callbacks
253
+ * and other options can depend on signals.
254
+ *
255
+ * @template TData - The type your `mutationFn` resolves to.
256
+ * @template TError - The type of errors your `mutationFn` may throw.
257
+ * @template TVariables - The type of the variables your `mutationFn` accepts.
258
+ * @template TOnMutateResult - The type returned by `onMutate`, passed on to `onSuccess`/`onError`/`onSettled`.
259
+ */
153
260
  export type UseMutationOptions<
154
261
  TData = unknown,
155
262
  TError = DefaultError,
@@ -168,6 +275,16 @@ export type UseMutateFunction<
168
275
  >
169
276
  ) => void
170
277
 
278
+ /**
279
+ * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
280
+ * promise which can be awaited.
281
+ *
282
+ * @template TData - The type your `mutationFn` resolves to.
283
+ * @template TError - The type of errors your `mutationFn` may throw.
284
+ * @template TVariables - The type of the variable passed to `mutateAsync`.
285
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
286
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
287
+ */
171
288
  export type UseMutateAsyncFunction<
172
289
  TData = unknown,
173
290
  TError = DefaultError,
@@ -175,6 +292,16 @@ export type UseMutateAsyncFunction<
175
292
  TOnMutateResult = unknown,
176
293
  > = MutateFunction<TData, TError, TVariables, TOnMutateResult>
177
294
 
295
+ /**
296
+ * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
297
+ * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
298
+ *
299
+ * @template TData - The type your `mutationFn` resolves to.
300
+ * @template TError - The type of errors your `mutationFn` may throw.
301
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
302
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
303
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
304
+ */
178
305
  export type UseBaseMutationResult<
179
306
  TData = unknown,
180
307
  TError = DefaultError,
@@ -184,6 +311,9 @@ export type UseBaseMutationResult<
184
311
  MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
185
312
  { mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }
186
313
  > & {
314
+ /**
315
+ * Similar to `mutate`, but returns a promise which can be awaited.
316
+ */
187
317
  mutateAsync: UseMutateAsyncFunction<
188
318
  TData,
189
319
  TError,
@@ -192,6 +322,15 @@ export type UseBaseMutationResult<
192
322
  >
193
323
  }
194
324
 
325
+ /**
326
+ * The result of `useMutation`. Same as {@link UseBaseMutationResult}.
327
+ *
328
+ * @template TData - The type your `mutationFn` resolves to.
329
+ * @template TError - The type of errors your `mutationFn` may throw.
330
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
331
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
332
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
333
+ */
195
334
  export type UseMutationResult<
196
335
  TData = unknown,
197
336
  TError = DefaultError,