@tanstack/solid-query 5.0.0-alpha.3 → 5.0.0-alpha.5

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.
Files changed (42) hide show
  1. package/build/cjs/index.js +15 -15
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/index.js +15 -15
  4. package/build/esm/index.js.map +1 -1
  5. package/build/source/__tests__/QueryClientProvider.test.jsx +2 -1
  6. package/build/source/__tests__/createInfiniteQuery.test.jsx +11 -10
  7. package/build/source/__tests__/createMutation.test.jsx +19 -18
  8. package/build/source/__tests__/createQueries.test.jsx +2 -18
  9. package/build/source/__tests__/createQuery.test.jsx +26 -25
  10. package/build/source/__tests__/suspense.test.jsx +6 -5
  11. package/build/source/__tests__/useIsFetching.test.jsx +2 -4
  12. package/build/source/__tests__/useIsMutating.test.jsx +25 -28
  13. package/build/source/__tests__/utils.jsx +3 -2
  14. package/build/source/createQueries.js +5 -5
  15. package/build/source/useIsFetching.js +5 -5
  16. package/build/source/useIsMutating.js +5 -5
  17. package/build/types/__tests__/utils.d.ts +2 -3
  18. package/build/types/createBaseQuery.d.ts +1 -1
  19. package/build/types/createInfiniteQuery.d.ts +2 -1
  20. package/build/types/createMutation.d.ts +2 -1
  21. package/build/types/createQueries.d.ts +3 -3
  22. package/build/types/useIsFetching.d.ts +1 -6
  23. package/build/types/useIsMutating.d.ts +1 -6
  24. package/build/umd/index.js +1 -1
  25. package/build/umd/index.js.map +1 -1
  26. package/package.json +4 -4
  27. package/src/__tests__/QueryClientProvider.test.tsx +2 -1
  28. package/src/__tests__/createInfiniteQuery.test.tsx +20 -18
  29. package/src/__tests__/createMutation.test.tsx +19 -18
  30. package/src/__tests__/createQueries.test.tsx +2 -24
  31. package/src/__tests__/createQuery.test.tsx +27 -25
  32. package/src/__tests__/suspense.test.tsx +6 -5
  33. package/src/__tests__/useIsFetching.test.tsx +2 -4
  34. package/src/__tests__/useIsMutating.test.tsx +32 -40
  35. package/src/__tests__/utils.tsx +3 -2
  36. package/src/createBaseQuery.ts +1 -1
  37. package/src/createInfiniteQuery.ts +2 -1
  38. package/src/createMutation.ts +2 -1
  39. package/src/createQueries.ts +8 -7
  40. package/src/createQuery.ts +2 -1
  41. package/src/useIsFetching.ts +8 -12
  42. package/src/useIsMutating.ts +8 -10
@@ -33,6 +33,8 @@ import {
33
33
  setActTimeout,
34
34
  sleep,
35
35
  } from './utils'
36
+ import { vi } from 'vitest'
37
+ import type { Mock } from 'vitest'
36
38
 
37
39
  describe('createQuery', () => {
38
40
  const queryCache = new QueryCache()
@@ -491,7 +493,7 @@ describe('createQuery', () => {
491
493
  it('should call onSuccess after a query has been fetched', async () => {
492
494
  const key = queryKey()
493
495
  const states: CreateQueryResult<string>[] = []
494
- const onSuccess = jest.fn()
496
+ const onSuccess = vi.fn()
495
497
 
496
498
  function Page() {
497
499
  const state = createQuery(() => ({
@@ -523,7 +525,7 @@ describe('createQuery', () => {
523
525
  it('should call onSuccess after a disabled query has been fetched', async () => {
524
526
  const key = queryKey()
525
527
  const states: CreateQueryResult<string>[] = []
526
- const onSuccess = jest.fn()
528
+ const onSuccess = vi.fn()
527
529
 
528
530
  function Page() {
529
531
  const state = createQuery(() => ({
@@ -561,7 +563,7 @@ describe('createQuery', () => {
561
563
  it('should not call onSuccess if a component has unmounted', async () => {
562
564
  const key = queryKey()
563
565
  const states: CreateQueryResult<string>[] = []
564
- const onSuccess = jest.fn()
566
+ const onSuccess = vi.fn()
565
567
 
566
568
  function Page() {
567
569
  const [show, setShow] = createSignal(true)
@@ -601,7 +603,7 @@ describe('createQuery', () => {
601
603
  it('should call onError after a query has been fetched with an error', async () => {
602
604
  const key = queryKey()
603
605
  const states: CreateQueryResult<unknown>[] = []
604
- const onError = jest.fn()
606
+ const onError = vi.fn()
605
607
 
606
608
  function Page() {
607
609
  const state = createQuery(() => ({
@@ -632,7 +634,7 @@ describe('createQuery', () => {
632
634
 
633
635
  it('should not call onError when receiving a CancelledError', async () => {
634
636
  const key = queryKey()
635
- const onError = jest.fn()
637
+ const onError = vi.fn()
636
638
 
637
639
  function Page() {
638
640
  const state = createQuery(() => ({
@@ -666,7 +668,7 @@ describe('createQuery', () => {
666
668
  it('should call onSettled after a query has been fetched', async () => {
667
669
  const key = queryKey()
668
670
  const states: CreateQueryResult<string>[] = []
669
- const onSettled = jest.fn()
671
+ const onSettled = vi.fn()
670
672
 
671
673
  function Page() {
672
674
  const state = createQuery(() => ({
@@ -696,7 +698,7 @@ describe('createQuery', () => {
696
698
  it('should call onSettled after a query has been fetched with an error', async () => {
697
699
  const key = queryKey()
698
700
  const states: CreateQueryResult<string>[] = []
699
- const onSettled = jest.fn()
701
+ const onSettled = vi.fn()
700
702
 
701
703
  function Page() {
702
704
  const state = createQuery(() => ({
@@ -2452,7 +2454,7 @@ describe('createQuery', () => {
2452
2454
 
2453
2455
  it('should not refetch query on focus when `enabled` is set to `false`', async () => {
2454
2456
  const key = queryKey()
2455
- const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
2457
+ const queryFn = vi.fn<unknown[], string>().mockReturnValue('data')
2456
2458
 
2457
2459
  function Page() {
2458
2460
  const { data = 'default' } = createQuery(() => ({
@@ -3296,7 +3298,7 @@ describe('createQuery', () => {
3296
3298
  it('should retry specified number of times', async () => {
3297
3299
  const key = queryKey()
3298
3300
 
3299
- const queryFn = jest.fn<unknown, unknown[]>()
3301
+ const queryFn = vi.fn<unknown[], unknown>()
3300
3302
  queryFn.mockImplementation(() => {
3301
3303
  return Promise.reject(new Error('Error test Barrett'))
3302
3304
  })
@@ -3337,7 +3339,7 @@ describe('createQuery', () => {
3337
3339
  it('should not retry if retry function `false`', async () => {
3338
3340
  const key = queryKey()
3339
3341
 
3340
- const queryFn = jest.fn<unknown, unknown[]>()
3342
+ const queryFn = vi.fn<unknown[], unknown>()
3341
3343
 
3342
3344
  queryFn.mockImplementationOnce(() => {
3343
3345
  return Promise.reject(new Error('Error test Tanner'))
@@ -3385,7 +3387,7 @@ describe('createQuery', () => {
3385
3387
 
3386
3388
  type DelayError = { delay: number }
3387
3389
 
3388
- const queryFn = jest.fn<unknown, unknown[]>()
3390
+ const queryFn = vi.fn<unknown[], unknown>()
3389
3391
  queryFn.mockImplementation(() => {
3390
3392
  return Promise.reject({ delay: 50 })
3391
3393
  })
@@ -3596,10 +3598,10 @@ describe('createQuery', () => {
3596
3598
  const key = queryKey()
3597
3599
  const states: CreateQueryResult<string>[] = []
3598
3600
 
3599
- const queryFn = jest.fn<string, unknown[]>()
3601
+ const queryFn = vi.fn<unknown[], string>()
3600
3602
  queryFn.mockImplementation(() => 'data')
3601
3603
 
3602
- const prefetchQueryFn = jest.fn<string, unknown[]>()
3604
+ const prefetchQueryFn = vi.fn<unknown[], string>()
3603
3605
  prefetchQueryFn.mockImplementation(() => 'not yet...')
3604
3606
 
3605
3607
  await queryClient.prefetchQuery({
@@ -3633,10 +3635,10 @@ describe('createQuery', () => {
3633
3635
  it('should not refetch if not stale after a prefetch', async () => {
3634
3636
  const key = queryKey()
3635
3637
 
3636
- const queryFn = jest.fn<string, unknown[]>()
3638
+ const queryFn = vi.fn<unknown[], string>()
3637
3639
  queryFn.mockImplementation(() => 'data')
3638
3640
 
3639
- const prefetchQueryFn = jest.fn<Promise<string>, unknown[]>()
3641
+ const prefetchQueryFn = vi.fn<unknown[], Promise<string>>()
3640
3642
  prefetchQueryFn.mockImplementation(async () => {
3641
3643
  await sleep(10)
3642
3644
  return 'not yet...'
@@ -3909,7 +3911,7 @@ describe('createQuery', () => {
3909
3911
 
3910
3912
  it('it should support enabled:false in query object syntax', async () => {
3911
3913
  const key = queryKey()
3912
- const queryFn = jest.fn<string, unknown[]>()
3914
+ const queryFn = vi.fn<unknown[], string>()
3913
3915
  queryFn.mockImplementation(() => 'data')
3914
3916
 
3915
3917
  function Page() {
@@ -3981,7 +3983,7 @@ describe('createQuery', () => {
3981
3983
  ))
3982
3984
 
3983
3985
  await waitFor(() => screen.getByText('fetched data'))
3984
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout')
3986
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout')
3985
3987
 
3986
3988
  result.unmount()
3987
3989
 
@@ -4007,7 +4009,7 @@ describe('createQuery', () => {
4007
4009
  ))
4008
4010
 
4009
4011
  await waitFor(() => screen.getByText('fetched data'))
4010
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout')
4012
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout')
4011
4013
 
4012
4014
  result.unmount()
4013
4015
 
@@ -4019,8 +4021,8 @@ describe('createQuery', () => {
4019
4021
 
4020
4022
  it('should not cause memo churn when data does not change', async () => {
4021
4023
  const key = queryKey()
4022
- const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
4023
- const memoFn = jest.fn()
4024
+ const queryFn = vi.fn<unknown[], string>().mockReturnValue('data')
4025
+ const memoFn = vi.fn()
4024
4026
 
4025
4027
  function Page() {
4026
4028
  const result = createQuery(() => ({
@@ -4255,7 +4257,7 @@ describe('createQuery', () => {
4255
4257
  it('should refetch if any query instance becomes enabled', async () => {
4256
4258
  const key = queryKey()
4257
4259
 
4258
- const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
4260
+ const queryFn = vi.fn<unknown[], string>().mockReturnValue('data')
4259
4261
 
4260
4262
  function Disabled() {
4261
4263
  createQuery(() => ({ queryKey: key, queryFn, enabled: false }))
@@ -4610,11 +4612,11 @@ describe('createQuery', () => {
4610
4612
 
4611
4613
  it('should cancel the query function when there are no more subscriptions', async () => {
4612
4614
  const key = queryKey()
4613
- let cancelFn: jest.Mock = jest.fn()
4615
+ let cancelFn: Mock = vi.fn()
4614
4616
 
4615
4617
  const queryFn = ({ signal }: { signal?: AbortSignal }) => {
4616
4618
  const promise = new Promise<string>((resolve, reject) => {
4617
- cancelFn = jest.fn(() => reject('Cancelled'))
4619
+ cancelFn = vi.fn(() => reject('Cancelled'))
4618
4620
  signal?.addEventListener('abort', cancelFn)
4619
4621
  sleep(20).then(() => resolve('OK'))
4620
4622
  })
@@ -4958,7 +4960,7 @@ describe('createQuery', () => {
4958
4960
  })
4959
4961
 
4960
4962
  it('should refetch when changed enabled to true in error state', async () => {
4961
- const queryFn = jest.fn<unknown, unknown[]>()
4963
+ const queryFn = vi.fn<unknown[], unknown>()
4962
4964
  queryFn.mockImplementation(async () => {
4963
4965
  await sleep(10)
4964
4966
  return Promise.reject(new Error('Suspense Error Bingo'))
@@ -6052,7 +6054,7 @@ describe('createQuery', () => {
6052
6054
 
6053
6055
  it('setQueryData - should not call onSuccess callback of active observers', async () => {
6054
6056
  const key = queryKey()
6055
- const onSuccess = jest.fn()
6057
+ const onSuccess = vi.fn()
6056
6058
 
6057
6059
  function Page() {
6058
6060
  const state = createQuery(() => ({
@@ -20,6 +20,7 @@ import {
20
20
  QueryClientProvider,
21
21
  } from '..'
22
22
  import { createQueryClient, queryKey, sleep } from './utils'
23
+ import { vi } from 'vitest'
23
24
 
24
25
  describe("useQuery's in Suspense mode", () => {
25
26
  const queryCache = new QueryCache()
@@ -142,7 +143,7 @@ describe("useQuery's in Suspense mode", () => {
142
143
  it('should not call the queryFn twice when used in Suspense mode', async () => {
143
144
  const key = queryKey()
144
145
 
145
- const queryFn = jest.fn<string, unknown[]>()
146
+ const queryFn = vi.fn<unknown[], string>()
146
147
  queryFn.mockImplementation(() => {
147
148
  sleep(10)
148
149
  return 'data'
@@ -219,7 +220,7 @@ describe("useQuery's in Suspense mode", () => {
219
220
  it('should call onSuccess on the first successful call', async () => {
220
221
  const key = queryKey()
221
222
 
222
- const successFn = jest.fn()
223
+ const successFn = vi.fn()
223
224
 
224
225
  function Page() {
225
226
  createQuery(() => ({
@@ -254,8 +255,8 @@ describe("useQuery's in Suspense mode", () => {
254
255
  it('should call every onSuccess handler within a suspense boundary', async () => {
255
256
  const key = queryKey()
256
257
 
257
- const successFn1 = jest.fn()
258
- const successFn2 = jest.fn()
258
+ const successFn1 = vi.fn()
259
+ const successFn2 = vi.fn()
259
260
 
260
261
  function FirstComponent() {
261
262
  createQuery(() => ({
@@ -733,7 +734,7 @@ describe("useQuery's in Suspense mode", () => {
733
734
  it('should not call the queryFn when not enabled', async () => {
734
735
  const key = queryKey()
735
736
 
736
- const queryFn = jest.fn<Promise<string>, unknown[]>()
737
+ const queryFn = vi.fn<unknown[], Promise<string>>()
737
738
  queryFn.mockImplementation(async () => {
738
739
  await sleep(10)
739
740
  return '23'
@@ -152,9 +152,7 @@ describe('useIsFetching', () => {
152
152
  function Page() {
153
153
  const [started, setStarted] = createSignal(false)
154
154
  const isFetching = useIsFetching(() => ({
155
- filters: {
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(() => ({ queryClient }))
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
- filters: {
120
- predicate: (mutation) =>
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 = jest
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
  })
@@ -2,6 +2,7 @@ import type { QueryClientConfig } from '@tanstack/query-core'
2
2
  import { QueryClient } from '@tanstack/query-core'
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 jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
38
+ return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
38
39
  }
39
40
 
40
41
  export function mockNavigatorOnLine(value: boolean) {
41
- return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
42
+ return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
42
43
  }
43
44
 
44
45
  export function sleep(timeout: number): Promise<void> {
@@ -37,7 +37,7 @@ export function createBaseQuery<
37
37
  CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
38
38
  >,
39
39
  Observer: typeof QueryObserver,
40
- queryClient?: () => QueryClient,
40
+ queryClient?: Accessor<QueryClient>,
41
41
  ) {
42
42
  const client = createMemo(() => useQueryClient(queryClient?.()))
43
43
 
@@ -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?: () => QueryClient,
31
+ queryClient?: Accessor<QueryClient>,
31
32
  ): CreateInfiniteQueryResult<TData, TError> {
32
33
  return createBaseQuery(
33
34
  createMemo(() => options()),
@@ -6,6 +6,7 @@ import type {
6
6
  CreateMutationOptions,
7
7
  CreateMutationResult,
8
8
  } from './types'
9
+ import type { Accessor } from 'solid-js'
9
10
  import { createComputed, onCleanup, on } from 'solid-js'
10
11
  import { createStore } from 'solid-js/store'
11
12
  import { shouldThrowError } from './utils'
@@ -18,7 +19,7 @@ export function createMutation<
18
19
  TContext = unknown,
19
20
  >(
20
21
  options: CreateMutationOptions<TData, TError, TVariables, TContext>,
21
- queryClient?: () => QueryClient,
22
+ queryClient?: Accessor<QueryClient>,
22
23
  ): CreateMutationResult<TData, TError, TVariables, TContext> {
23
24
  const client = useQueryClient(queryClient?.())
24
25
 
@@ -6,6 +6,7 @@ import type {
6
6
  DefaultError,
7
7
  } from '@tanstack/query-core'
8
8
  import { notifyManager, QueriesObserver } from '@tanstack/query-core'
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
- queryClient?: QueryClient
154
- },
154
+ }>,
155
+ queryClient?: Accessor<QueryClient>,
155
156
  ): QueriesResults<T> {
156
- const queryClient = useQueryClient(queriesOptions().queryClient)
157
+ const client = useQueryClient(queryClient?.())
157
158
 
158
159
  const defaultedQueries = queriesOptions().queries.map((options) => {
159
- const defaultedOptions = queryClient.defaultQueryOptions(options)
160
+ const defaultedOptions = client.defaultQueryOptions(options)
160
161
  defaultedOptions._optimisticResults = 'optimistic'
161
162
  return defaultedOptions
162
163
  })
163
164
 
164
- const observer = new QueriesObserver(queryClient, defaultedQueries)
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 = queryClient.defaultQueryOptions(options)
185
+ const defaultedOptions = client.defaultQueryOptions(options)
185
186
  defaultedOptions._optimisticResults = 'optimistic'
186
187
  return defaultedOptions
187
188
  })
@@ -1,5 +1,6 @@
1
1
  import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
2
2
  import { QueryObserver } from '@tanstack/query-core'
3
+ import type { Accessor } from 'solid-js'
3
4
  import { createMemo } from 'solid-js'
4
5
  import { createBaseQuery } from './createBaseQuery'
5
6
  import type {
@@ -58,7 +59,7 @@ export function createQuery<
58
59
  TQueryKey extends QueryKey = QueryKey,
59
60
  >(
60
61
  options: CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
61
- queryClient?: () => QueryClient,
62
+ queryClient?: Accessor<QueryClient>,
62
63
  ) {
63
64
  return createBaseQuery(
64
65
  createMemo(() => options()),
@@ -3,21 +3,17 @@ import type { Accessor } from 'solid-js'
3
3
  import { createMemo, createSignal, onCleanup } from 'solid-js'
4
4
  import { useQueryClient } from './QueryClientProvider'
5
5
 
6
- type Options = () => {
7
- filters?: QueryFilters
8
- queryClient?: QueryClient
9
- }
10
-
11
- export function useIsFetching(options: Options = () => ({})): Accessor<number> {
12
- const queryClient = createMemo(() => useQueryClient(options().queryClient))
13
- const queryCache = createMemo(() => queryClient().getQueryCache())
6
+ export function useIsFetching(
7
+ filters?: Accessor<QueryFilters>,
8
+ queryClient?: Accessor<QueryClient>,
9
+ ): Accessor<number> {
10
+ const client = createMemo(() => useQueryClient(queryClient?.()))
11
+ const queryCache = createMemo(() => client().getQueryCache())
14
12
 
15
- const [fetches, setFetches] = createSignal(
16
- queryClient().isFetching(options().filters),
17
- )
13
+ const [fetches, setFetches] = createSignal(client().isFetching(filters?.()))
18
14
 
19
15
  const unsubscribe = queryCache().subscribe(() => {
20
- setFetches(queryClient().isFetching(options().filters))
16
+ setFetches(client().isFetching(filters?.()))
21
17
  })
22
18
 
23
19
  onCleanup(unsubscribe)
@@ -3,21 +3,19 @@ import { useQueryClient } from './QueryClientProvider'
3
3
  import type { Accessor } from 'solid-js'
4
4
  import { createSignal, onCleanup, createMemo } from 'solid-js'
5
5
 
6
- type Options = () => {
7
- filters?: MutationFilters
8
- queryClient?: QueryClient
9
- }
10
-
11
- export function useIsMutating(options: Options = () => ({})): Accessor<number> {
12
- const queryClient = createMemo(() => useQueryClient(options().queryClient))
13
- const mutationCache = createMemo(() => queryClient().getMutationCache())
6
+ export function useIsMutating(
7
+ filters?: Accessor<MutationFilters>,
8
+ queryClient?: Accessor<QueryClient>,
9
+ ): Accessor<number> {
10
+ const client = createMemo(() => useQueryClient(queryClient?.()))
11
+ const mutationCache = createMemo(() => client().getMutationCache())
14
12
 
15
13
  const [mutations, setMutations] = createSignal(
16
- queryClient().isMutating(options().filters),
14
+ client().isMutating(filters?.()),
17
15
  )
18
16
 
19
17
  const unsubscribe = mutationCache().subscribe((_result) => {
20
- setMutations(queryClient().isMutating(options().filters))
18
+ setMutations(client().isMutating(filters?.()))
21
19
  })
22
20
 
23
21
  onCleanup(unsubscribe)