@tanstack/solid-query 5.0.0-alpha.2 → 5.0.0-alpha.21
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/cjs/index.js +73 -34
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +75 -37
- package/build/esm/index.js.map +1 -1
- package/build/source/QueryClient.js +6 -0
- package/build/source/__tests__/QueryClientProvider.test.jsx +2 -1
- package/build/source/__tests__/createInfiniteQuery.test.jsx +67 -20
- package/build/source/__tests__/createMutation.test.jsx +19 -18
- package/build/source/__tests__/createQueries.test.jsx +4 -91
- package/build/source/__tests__/createQuery.test.jsx +62 -271
- package/build/source/__tests__/suspense.test.jsx +3 -64
- package/build/source/__tests__/useIsFetching.test.jsx +2 -4
- package/build/source/__tests__/useIsMutating.test.jsx +25 -28
- package/build/source/__tests__/utils.jsx +4 -3
- package/build/source/createBaseQuery.js +45 -19
- package/build/source/createQueries.js +5 -5
- package/build/source/index.js +1 -0
- package/build/source/useIsFetching.js +5 -5
- package/build/source/useIsMutating.js +5 -5
- package/build/types/QueryClient.d.ts +29 -0
- package/build/types/QueryClientProvider.d.ts +1 -1
- package/build/types/__tests__/utils.d.ts +3 -4
- package/build/types/createBaseQuery.d.ts +3 -2
- package/build/types/createInfiniteQuery.d.ts +4 -2
- package/build/types/createMutation.d.ts +4 -2
- package/build/types/createQueries.d.ts +5 -4
- package/build/types/createQuery.d.ts +2 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/types.d.ts +2 -1
- package/build/types/useIsFetching.d.ts +3 -7
- package/build/types/useIsMutating.d.ts +3 -7
- package/build/umd/index.js +1 -1
- package/build/umd/index.js.map +1 -1
- package/package.json +5 -5
- package/src/QueryClient.ts +84 -0
- package/src/QueryClientProvider.tsx +1 -1
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/createInfiniteQuery.test.tsx +95 -34
- package/src/__tests__/createMutation.test.tsx +19 -18
- package/src/__tests__/createQueries.test.tsx +4 -97
- package/src/__tests__/createQuery.test.tsx +78 -344
- package/src/__tests__/suspense.test.tsx +3 -85
- package/src/__tests__/useIsFetching.test.tsx +2 -4
- package/src/__tests__/useIsMutating.test.tsx +32 -40
- package/src/__tests__/utils.tsx +4 -3
- package/src/createBaseQuery.ts +70 -25
- package/src/createInfiniteQuery.ts +3 -2
- package/src/createMutation.ts +4 -2
- package/src/createQueries.ts +9 -8
- package/src/createQuery.ts +4 -2
- package/src/index.ts +7 -0
- package/src/types.ts +4 -2
- package/src/useIsFetching.ts +10 -13
- package/src/useIsMutating.ts +10 -11
|
@@ -152,9 +152,7 @@ describe('useIsFetching', () => {
|
|
|
152
152
|
function Page() {
|
|
153
153
|
const [started, setStarted] = createSignal(false)
|
|
154
154
|
const isFetching = useIsFetching(() => ({
|
|
155
|
-
|
|
156
|
-
queryKey: key1,
|
|
157
|
-
},
|
|
155
|
+
queryKey: key1,
|
|
158
156
|
}))
|
|
159
157
|
|
|
160
158
|
createRenderEffect(() => {
|
|
@@ -237,7 +235,7 @@ describe('useIsFetching', () => {
|
|
|
237
235
|
() => queryClient,
|
|
238
236
|
)
|
|
239
237
|
|
|
240
|
-
const isFetching = useIsFetching(() =>
|
|
238
|
+
const isFetching = useIsFetching(undefined, () => queryClient)
|
|
241
239
|
|
|
242
240
|
return (
|
|
243
241
|
<div>
|
|
@@ -6,6 +6,7 @@ import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js'
|
|
|
6
6
|
import { render } from 'solid-testing-library'
|
|
7
7
|
import * as MutationCacheModule from '../../../query-core/src/mutationCache'
|
|
8
8
|
import { setActTimeout } from './utils'
|
|
9
|
+
import { vi } from 'vitest'
|
|
9
10
|
|
|
10
11
|
describe('useIsMutating', () => {
|
|
11
12
|
it('should return the number of fetching mutations', async () => {
|
|
@@ -68,9 +69,7 @@ describe('useIsMutating', () => {
|
|
|
68
69
|
const queryClient = createQueryClient()
|
|
69
70
|
|
|
70
71
|
function IsMutating() {
|
|
71
|
-
const isMutating = useIsMutating(() => ({
|
|
72
|
-
filters: { mutationKey: ['mutation1'] },
|
|
73
|
-
}))
|
|
72
|
+
const isMutating = useIsMutating(() => ({ mutationKey: ['mutation1'] }))
|
|
74
73
|
createRenderEffect(() => {
|
|
75
74
|
isMutatings.push(isMutating())
|
|
76
75
|
})
|
|
@@ -116,10 +115,8 @@ describe('useIsMutating', () => {
|
|
|
116
115
|
|
|
117
116
|
function IsMutating() {
|
|
118
117
|
const isMutating = useIsMutating(() => ({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
mutation.options.mutationKey?.[0] === 'mutation1',
|
|
122
|
-
},
|
|
118
|
+
predicate: (mutation) =>
|
|
119
|
+
mutation.options.mutationKey?.[0] === 'mutation1',
|
|
123
120
|
}))
|
|
124
121
|
createRenderEffect(() => {
|
|
125
122
|
isMutatings.push(isMutating())
|
|
@@ -161,6 +158,33 @@ describe('useIsMutating', () => {
|
|
|
161
158
|
await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]))
|
|
162
159
|
})
|
|
163
160
|
|
|
161
|
+
it('should use provided custom queryClient', async () => {
|
|
162
|
+
const queryClient = createQueryClient()
|
|
163
|
+
function Page() {
|
|
164
|
+
const isMutating = useIsMutating(undefined, () => queryClient)
|
|
165
|
+
const { mutate } = createMutation(
|
|
166
|
+
() => ({
|
|
167
|
+
mutationKey: ['mutation1'],
|
|
168
|
+
mutationFn: async () => {
|
|
169
|
+
await sleep(10)
|
|
170
|
+
return 'data'
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
() => queryClient,
|
|
174
|
+
)
|
|
175
|
+
createEffect(() => {
|
|
176
|
+
mutate()
|
|
177
|
+
})
|
|
178
|
+
return (
|
|
179
|
+
<div>
|
|
180
|
+
<div>mutating: {isMutating}</div>
|
|
181
|
+
</div>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
render(() => <Page></Page>)
|
|
185
|
+
await waitFor(() => screen.findByText('mutating: 1'))
|
|
186
|
+
})
|
|
187
|
+
|
|
164
188
|
it('should not change state if unmounted', async () => {
|
|
165
189
|
// We have to mock the MutationCache to not unsubscribe
|
|
166
190
|
// the listener when the component is unmounted
|
|
@@ -171,7 +195,7 @@ describe('useIsMutating', () => {
|
|
|
171
195
|
}
|
|
172
196
|
}
|
|
173
197
|
|
|
174
|
-
const MutationCacheSpy =
|
|
198
|
+
const MutationCacheSpy = vi
|
|
175
199
|
.spyOn(MutationCacheModule, 'MutationCache')
|
|
176
200
|
.mockImplementation((fn) => {
|
|
177
201
|
return new MutationCacheMock(fn)
|
|
@@ -221,36 +245,4 @@ describe('useIsMutating', () => {
|
|
|
221
245
|
await sleep(20)
|
|
222
246
|
MutationCacheSpy.mockRestore()
|
|
223
247
|
})
|
|
224
|
-
|
|
225
|
-
it('should use provided custom queryClient', async () => {
|
|
226
|
-
const queryClient = createQueryClient()
|
|
227
|
-
|
|
228
|
-
function Page() {
|
|
229
|
-
const isMutating = useIsMutating(() => ({ queryClient }))
|
|
230
|
-
const { mutate } = createMutation(
|
|
231
|
-
() => ({
|
|
232
|
-
mutationKey: ['mutation1'],
|
|
233
|
-
mutationFn: async () => {
|
|
234
|
-
await sleep(10)
|
|
235
|
-
return 'data'
|
|
236
|
-
},
|
|
237
|
-
}),
|
|
238
|
-
() => queryClient,
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
createEffect(() => {
|
|
242
|
-
mutate()
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
return (
|
|
246
|
-
<div>
|
|
247
|
-
<div>mutating: {isMutating}</div>
|
|
248
|
-
</div>
|
|
249
|
-
)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
render(() => <Page></Page>)
|
|
253
|
-
|
|
254
|
-
await waitFor(() => screen.findByText('mutating: 1'))
|
|
255
|
-
})
|
|
256
248
|
})
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { QueryClientConfig } from '@tanstack/query-core'
|
|
2
|
-
import { QueryClient } from '
|
|
2
|
+
import { QueryClient } from '../QueryClient'
|
|
3
3
|
import type { ParentProps } from 'solid-js'
|
|
4
4
|
import { createEffect, createSignal, onCleanup, Show } from 'solid-js'
|
|
5
|
+
import { vi } from 'vitest'
|
|
5
6
|
|
|
6
7
|
let queryKeyCount = 0
|
|
7
8
|
export function queryKey(): Array<string> {
|
|
@@ -34,11 +35,11 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function mockVisibilityState(value: DocumentVisibilityState) {
|
|
37
|
-
return
|
|
38
|
+
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function mockNavigatorOnLine(value: boolean) {
|
|
41
|
-
return
|
|
42
|
+
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export function sleep(timeout: number): Promise<void> {
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
// in solid-js/web package. I'll create a GitHub issue with them to see
|
|
4
4
|
// why that happens.
|
|
5
5
|
import type {
|
|
6
|
-
QueryClient,
|
|
7
6
|
QueryKey,
|
|
8
7
|
QueryObserver,
|
|
9
8
|
QueryObserverResult,
|
|
10
9
|
} from '@tanstack/query-core'
|
|
10
|
+
import type { QueryClient } from './QueryClient'
|
|
11
11
|
import { hydrate } from '@tanstack/query-core'
|
|
12
12
|
import { notifyManager } from '@tanstack/query-core'
|
|
13
13
|
import type { Accessor } from 'solid-js'
|
|
@@ -18,13 +18,29 @@ import {
|
|
|
18
18
|
createResource,
|
|
19
19
|
on,
|
|
20
20
|
onCleanup,
|
|
21
|
-
onMount,
|
|
22
21
|
} from 'solid-js'
|
|
23
|
-
import { createStore, unwrap } from 'solid-js/store'
|
|
22
|
+
import { createStore, reconcile, unwrap } from 'solid-js/store'
|
|
24
23
|
import { useQueryClient } from './QueryClientProvider'
|
|
25
24
|
import type { CreateBaseQueryOptions } from './types'
|
|
26
25
|
import { shouldThrowError } from './utils'
|
|
27
26
|
|
|
27
|
+
function reconcileFn<TData, TError>(
|
|
28
|
+
store: QueryObserverResult<TData, TError>,
|
|
29
|
+
result: QueryObserverResult<TData, TError>,
|
|
30
|
+
reconcileOption:
|
|
31
|
+
| string
|
|
32
|
+
| false
|
|
33
|
+
| ((oldData: TData | undefined, newData: TData) => TData),
|
|
34
|
+
): QueryObserverResult<TData, TError> {
|
|
35
|
+
if (reconcileOption === false) return result
|
|
36
|
+
if (typeof reconcileOption === 'function') {
|
|
37
|
+
const newData = reconcileOption(store.data, result.data as TData)
|
|
38
|
+
return { ...result, data: newData } as typeof result
|
|
39
|
+
}
|
|
40
|
+
const newData = reconcile(result.data, { key: reconcileOption })(store.data)
|
|
41
|
+
return { ...result, data: newData } as typeof result
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
// Base Query Function that is used to create the query.
|
|
29
45
|
export function createBaseQuery<
|
|
30
46
|
TQueryFnData,
|
|
@@ -37,12 +53,13 @@ export function createBaseQuery<
|
|
|
37
53
|
CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
|
|
38
54
|
>,
|
|
39
55
|
Observer: typeof QueryObserver,
|
|
40
|
-
queryClient?:
|
|
56
|
+
queryClient?: Accessor<QueryClient>,
|
|
41
57
|
) {
|
|
42
58
|
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
43
59
|
|
|
44
60
|
const defaultedOptions = client().defaultQueryOptions(options())
|
|
45
61
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
62
|
+
defaultedOptions.structuralSharing = false
|
|
46
63
|
if (isServer) {
|
|
47
64
|
defaultedOptions.retry = false
|
|
48
65
|
defaultedOptions.throwErrors = true
|
|
@@ -64,7 +81,21 @@ export function createBaseQuery<
|
|
|
64
81
|
) => {
|
|
65
82
|
return observer.subscribe((result) => {
|
|
66
83
|
notifyManager.batchCalls(() => {
|
|
67
|
-
const
|
|
84
|
+
const query = observer.getCurrentQuery()
|
|
85
|
+
const { refetch, ...rest } = unwrap(result)
|
|
86
|
+
const unwrappedResult = {
|
|
87
|
+
...rest,
|
|
88
|
+
|
|
89
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
90
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
91
|
+
// copying over the missing properties from state in order to support hydration
|
|
92
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
93
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
94
|
+
fetchFailureReason: query.state.fetchFailureReason,
|
|
95
|
+
fetchMeta: query.state.fetchMeta,
|
|
96
|
+
isInvalidated: query.state.isInvalidated,
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
if (unwrappedResult.isError) {
|
|
69
100
|
if (process.env['NODE_ENV'] === 'development') {
|
|
70
101
|
console.error(unwrappedResult.error)
|
|
@@ -72,7 +103,9 @@ export function createBaseQuery<
|
|
|
72
103
|
reject(unwrappedResult.error)
|
|
73
104
|
}
|
|
74
105
|
if (unwrappedResult.isSuccess) {
|
|
75
|
-
|
|
106
|
+
// Use of any here is fine
|
|
107
|
+
// We cannot include refetch since it is not serializable
|
|
108
|
+
resolve(unwrappedResult as any)
|
|
76
109
|
}
|
|
77
110
|
})()
|
|
78
111
|
})
|
|
@@ -81,18 +114,28 @@ export function createBaseQuery<
|
|
|
81
114
|
const createClientSubscriber = () => {
|
|
82
115
|
return observer.subscribe((result) => {
|
|
83
116
|
notifyManager.batchCalls(() => {
|
|
84
|
-
|
|
117
|
+
// @ts-expect-error - This will error because the reconcile option does not
|
|
118
|
+
// exist on the query-core QueryObserverResult type
|
|
119
|
+
const reconcileOptions = observer.options.reconcile
|
|
85
120
|
// If the query has data we dont suspend but instead mutate the resource
|
|
86
121
|
// This could happen when placeholderData/initialData is defined
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
123
|
+
setState((store) => {
|
|
124
|
+
return reconcileFn(
|
|
125
|
+
store,
|
|
126
|
+
result,
|
|
127
|
+
reconcileOptions === undefined ? 'id' : reconcileOptions,
|
|
128
|
+
)
|
|
129
|
+
})
|
|
93
130
|
mutate(state)
|
|
94
131
|
} else {
|
|
95
|
-
setState(
|
|
132
|
+
setState((store) => {
|
|
133
|
+
return reconcileFn(
|
|
134
|
+
store,
|
|
135
|
+
result,
|
|
136
|
+
reconcileOptions === undefined ? 'id' : reconcileOptions,
|
|
137
|
+
)
|
|
138
|
+
})
|
|
96
139
|
refetch()
|
|
97
140
|
}
|
|
98
141
|
})()
|
|
@@ -178,13 +221,17 @@ export function createBaseQuery<
|
|
|
178
221
|
}
|
|
179
222
|
})
|
|
180
223
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
224
|
+
createComputed(
|
|
225
|
+
on(
|
|
226
|
+
() => client().defaultQueryOptions(options()),
|
|
227
|
+
() => observer.setOptions(client().defaultQueryOptions(options())),
|
|
228
|
+
{
|
|
229
|
+
// Defer because we don't need to trigger on first render
|
|
230
|
+
// This only cares about changes to options after the observer is created
|
|
231
|
+
defer: true,
|
|
232
|
+
},
|
|
233
|
+
),
|
|
234
|
+
)
|
|
188
235
|
|
|
189
236
|
createComputed(
|
|
190
237
|
on(
|
|
@@ -209,10 +256,8 @@ export function createBaseQuery<
|
|
|
209
256
|
target: QueryObserverResult<TData, TError>,
|
|
210
257
|
prop: keyof QueryObserverResult<TData, TError>,
|
|
211
258
|
): any {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return Reflect.get(target, prop)
|
|
259
|
+
const val = queryResource()?.[prop]
|
|
260
|
+
return val !== undefined ? val : Reflect.get(target, prop)
|
|
216
261
|
},
|
|
217
262
|
}
|
|
218
263
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
QueryObserver,
|
|
3
3
|
QueryKey,
|
|
4
|
-
QueryClient,
|
|
5
4
|
DefaultError,
|
|
6
5
|
InfiniteData,
|
|
7
6
|
} from '@tanstack/query-core'
|
|
7
|
+
import type { QueryClient } from './QueryClient'
|
|
8
8
|
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
9
9
|
import type {
|
|
10
10
|
CreateInfiniteQueryOptions,
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
} from './types'
|
|
13
13
|
import { createBaseQuery } from './createBaseQuery'
|
|
14
14
|
import { createMemo } from 'solid-js'
|
|
15
|
+
import type { Accessor } from 'solid-js'
|
|
15
16
|
|
|
16
17
|
export function createInfiniteQuery<
|
|
17
18
|
TQueryFnData,
|
|
@@ -27,7 +28,7 @@ export function createInfiniteQuery<
|
|
|
27
28
|
TQueryKey,
|
|
28
29
|
TPageParam
|
|
29
30
|
>,
|
|
30
|
-
queryClient?:
|
|
31
|
+
queryClient?: Accessor<QueryClient>,
|
|
31
32
|
): CreateInfiniteQueryResult<TData, TError> {
|
|
32
33
|
return createBaseQuery(
|
|
33
34
|
createMemo(() => options()),
|
package/src/createMutation.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DefaultError } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import { MutationObserver } from '@tanstack/query-core'
|
|
3
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
4
5
|
import type {
|
|
@@ -6,6 +7,7 @@ import type {
|
|
|
6
7
|
CreateMutationOptions,
|
|
7
8
|
CreateMutationResult,
|
|
8
9
|
} from './types'
|
|
10
|
+
import type { Accessor } from 'solid-js'
|
|
9
11
|
import { createComputed, onCleanup, on } from 'solid-js'
|
|
10
12
|
import { createStore } from 'solid-js/store'
|
|
11
13
|
import { shouldThrowError } from './utils'
|
|
@@ -18,7 +20,7 @@ export function createMutation<
|
|
|
18
20
|
TContext = unknown,
|
|
19
21
|
>(
|
|
20
22
|
options: CreateMutationOptions<TData, TError, TVariables, TContext>,
|
|
21
|
-
queryClient?:
|
|
23
|
+
queryClient?: Accessor<QueryClient>,
|
|
22
24
|
): CreateMutationResult<TData, TError, TVariables, TContext> {
|
|
23
25
|
const client = useQueryClient(queryClient?.())
|
|
24
26
|
|
package/src/createQueries.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
QueriesPlaceholderDataFunction,
|
|
3
|
-
QueryClient,
|
|
4
3
|
QueryFunction,
|
|
5
4
|
QueryKey,
|
|
6
5
|
DefaultError,
|
|
7
6
|
} from '@tanstack/query-core'
|
|
8
7
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
8
|
+
import type { QueryClient } from './QueryClient'
|
|
9
|
+
import type { Accessor } from 'solid-js'
|
|
9
10
|
import { createComputed, onCleanup, onMount } from 'solid-js'
|
|
10
11
|
import { createStore, unwrap } from 'solid-js/store'
|
|
11
12
|
import { useQueryClient } from './QueryClientProvider'
|
|
@@ -148,20 +149,20 @@ export type QueriesResults<
|
|
|
148
149
|
CreateQueryResult[]
|
|
149
150
|
|
|
150
151
|
export function createQueries<T extends any[]>(
|
|
151
|
-
queriesOptions:
|
|
152
|
+
queriesOptions: Accessor<{
|
|
152
153
|
queries: readonly [...QueriesOptions<T>]
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
}>,
|
|
155
|
+
queryClient?: Accessor<QueryClient>,
|
|
155
156
|
): QueriesResults<T> {
|
|
156
|
-
const
|
|
157
|
+
const client = useQueryClient(queryClient?.())
|
|
157
158
|
|
|
158
159
|
const defaultedQueries = queriesOptions().queries.map((options) => {
|
|
159
|
-
const defaultedOptions =
|
|
160
|
+
const defaultedOptions = client.defaultQueryOptions(options)
|
|
160
161
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
161
162
|
return defaultedOptions
|
|
162
163
|
})
|
|
163
164
|
|
|
164
|
-
const observer = new QueriesObserver(
|
|
165
|
+
const observer = new QueriesObserver(client, defaultedQueries)
|
|
165
166
|
|
|
166
167
|
const [state, setState] = createStore(
|
|
167
168
|
observer.getOptimisticResult(defaultedQueries),
|
|
@@ -181,7 +182,7 @@ export function createQueries<T extends any[]>(
|
|
|
181
182
|
|
|
182
183
|
createComputed(() => {
|
|
183
184
|
const updatedQueries = queriesOptions().queries.map((options) => {
|
|
184
|
-
const defaultedOptions =
|
|
185
|
+
const defaultedOptions = client.defaultQueryOptions(options)
|
|
185
186
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
186
187
|
return defaultedOptions
|
|
187
188
|
})
|
package/src/createQuery.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryKey, DefaultError } from '@tanstack/query-core'
|
|
2
2
|
import { QueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import type { QueryClient } from './QueryClient'
|
|
4
|
+
import type { Accessor } from 'solid-js'
|
|
3
5
|
import { createMemo } from 'solid-js'
|
|
4
6
|
import { createBaseQuery } from './createBaseQuery'
|
|
5
7
|
import type {
|
|
@@ -58,7 +60,7 @@ export function createQuery<
|
|
|
58
60
|
TQueryKey extends QueryKey = QueryKey,
|
|
59
61
|
>(
|
|
60
62
|
options: CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
61
|
-
queryClient?:
|
|
63
|
+
queryClient?: Accessor<QueryClient>,
|
|
62
64
|
) {
|
|
63
65
|
return createBaseQuery(
|
|
64
66
|
createMemo(() => options()),
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,13 @@ export * from '@tanstack/query-core'
|
|
|
8
8
|
|
|
9
9
|
// Solid Query
|
|
10
10
|
export * from './types'
|
|
11
|
+
export { QueryClient } from './QueryClient'
|
|
12
|
+
export type {
|
|
13
|
+
QueryObserverOptions,
|
|
14
|
+
DefaultOptions,
|
|
15
|
+
QueryClientConfig,
|
|
16
|
+
InfiniteQueryObserverOptions,
|
|
17
|
+
} from './QueryClient'
|
|
11
18
|
export { createQuery } from './createQuery'
|
|
12
19
|
export {
|
|
13
20
|
QueryClientContext,
|
package/src/types.ts
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
QueryKey,
|
|
5
|
-
QueryObserverOptions,
|
|
6
5
|
QueryObserverResult,
|
|
7
6
|
MutateFunction,
|
|
8
7
|
MutationObserverOptions,
|
|
9
8
|
MutationObserverResult,
|
|
10
9
|
DefinedQueryObserverResult,
|
|
11
|
-
InfiniteQueryObserverOptions,
|
|
12
10
|
InfiniteQueryObserverResult,
|
|
13
11
|
WithRequired,
|
|
14
12
|
DefaultError,
|
|
15
13
|
} from '@tanstack/query-core'
|
|
14
|
+
import type {
|
|
15
|
+
QueryObserverOptions,
|
|
16
|
+
InfiniteQueryObserverOptions,
|
|
17
|
+
} from './QueryClient'
|
|
16
18
|
|
|
17
19
|
export type FunctionedParams<T> = () => T
|
|
18
20
|
|
package/src/useIsFetching.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryFilters } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import type { Accessor } from 'solid-js'
|
|
3
4
|
import { createMemo, createSignal, onCleanup } from 'solid-js'
|
|
4
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
filters?: QueryFilters
|
|
8
|
-
queryClient?: QueryClient
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const queryClient = createMemo(() => useQueryClient(options().queryClient))
|
|
13
|
-
const queryCache = createMemo(() => queryClient().getQueryCache())
|
|
7
|
+
export function useIsFetching(
|
|
8
|
+
filters?: Accessor<QueryFilters>,
|
|
9
|
+
queryClient?: Accessor<QueryClient>,
|
|
10
|
+
): Accessor<number> {
|
|
11
|
+
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
12
|
+
const queryCache = createMemo(() => client().getQueryCache())
|
|
14
13
|
|
|
15
|
-
const [fetches, setFetches] = createSignal(
|
|
16
|
-
queryClient().isFetching(options().filters),
|
|
17
|
-
)
|
|
14
|
+
const [fetches, setFetches] = createSignal(client().isFetching(filters?.()))
|
|
18
15
|
|
|
19
16
|
const unsubscribe = queryCache().subscribe(() => {
|
|
20
|
-
setFetches(
|
|
17
|
+
setFetches(client().isFetching(filters?.()))
|
|
21
18
|
})
|
|
22
19
|
|
|
23
20
|
onCleanup(unsubscribe)
|
package/src/useIsMutating.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import type { MutationFilters
|
|
1
|
+
import type { MutationFilters } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import { useQueryClient } from './QueryClientProvider'
|
|
3
4
|
import type { Accessor } from 'solid-js'
|
|
4
5
|
import { createSignal, onCleanup, createMemo } from 'solid-js'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
filters?: MutationFilters
|
|
8
|
-
queryClient?: QueryClient
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const queryClient = createMemo(() => useQueryClient(options().queryClient))
|
|
13
|
-
const mutationCache = createMemo(() => queryClient().getMutationCache())
|
|
7
|
+
export function useIsMutating(
|
|
8
|
+
filters?: Accessor<MutationFilters>,
|
|
9
|
+
queryClient?: Accessor<QueryClient>,
|
|
10
|
+
): Accessor<number> {
|
|
11
|
+
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
12
|
+
const mutationCache = createMemo(() => client().getMutationCache())
|
|
14
13
|
|
|
15
14
|
const [mutations, setMutations] = createSignal(
|
|
16
|
-
|
|
15
|
+
client().isMutating(filters?.()),
|
|
17
16
|
)
|
|
18
17
|
|
|
19
18
|
const unsubscribe = mutationCache().subscribe((_result) => {
|
|
20
|
-
setMutations(
|
|
19
|
+
setMutations(client().isMutating(filters?.()))
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
onCleanup(unsubscribe)
|