@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
@@ -3,6 +3,7 @@ import { createEffect, createRenderEffect, createSignal, ErrorBoundary, } from '
3
3
  import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
4
4
  import { createMutation, MutationCache, QueryCache, QueryClientProvider, } from '..';
5
5
  import { createQueryClient, mockNavigatorOnLine, queryKey, setActTimeout, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('createMutation', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const mutationCache = new MutationCache();
@@ -63,8 +64,8 @@ describe('createMutation', () => {
63
64
  });
64
65
  it('should be able to call `onSuccess` and `onSettled` after each successful mutate', async () => {
65
66
  const [count, setCount] = createSignal(0);
66
- const onSuccessMock = jest.fn();
67
- const onSettledMock = jest.fn();
67
+ const onSuccessMock = vi.fn();
68
+ const onSettledMock = vi.fn();
68
69
  function Page() {
69
70
  const mutation = createMutation(() => ({
70
71
  mutationFn: (vars) => Promise.resolve(vars.count),
@@ -110,7 +111,7 @@ describe('createMutation', () => {
110
111
  });
111
112
  it('should set correct values for `failureReason` and `failureCount` on multiple mutate calls', async () => {
112
113
  const [count, setCount] = createSignal(0);
113
- const mutateFn = jest.fn();
114
+ const mutateFn = vi.fn();
114
115
  mutateFn.mockImplementationOnce(() => {
115
116
  return Promise.reject(new Error('Error test Jonas'));
116
117
  });
@@ -152,8 +153,8 @@ describe('createMutation', () => {
152
153
  await waitFor(() => screen.getByText('Failed because null'));
153
154
  });
154
155
  it('should be able to call `onError` and `onSettled` after each failed mutate', async () => {
155
- const onErrorMock = jest.fn();
156
- const onSettledMock = jest.fn();
156
+ const onErrorMock = vi.fn();
157
+ const onSettledMock = vi.fn();
157
158
  const [count, setCount] = createSignal(0);
158
159
  function Page() {
159
160
  const mutation = createMutation(() => ({
@@ -388,7 +389,7 @@ describe('createMutation', () => {
388
389
  });
389
390
  it('should call onMutate even if paused', async () => {
390
391
  const onlineMock = mockNavigatorOnLine(false);
391
- const onMutate = jest.fn();
392
+ const onMutate = vi.fn();
392
393
  let count = 0;
393
394
  function Page() {
394
395
  const mutation = createMutation(() => ({
@@ -617,8 +618,8 @@ describe('createMutation', () => {
617
618
  });
618
619
  });
619
620
  it('should pass meta to mutation', async () => {
620
- const errorMock = jest.fn();
621
- const successMock = jest.fn();
621
+ const errorMock = vi.fn();
622
+ const successMock = vi.fn();
622
623
  const queryClientMutationMeta = createQueryClient({
623
624
  mutationCache: new MutationCache({
624
625
  onSuccess: (_, __, ___, mutation) => {
@@ -664,10 +665,10 @@ describe('createMutation', () => {
664
665
  expect(errorMock).toHaveBeenCalledWith(metaErrorMessage);
665
666
  });
666
667
  it('should call cache callbacks when unmounted', async () => {
667
- const onSuccess = jest.fn();
668
- const onSuccessMutate = jest.fn();
669
- const onSettled = jest.fn();
670
- const onSettledMutate = jest.fn();
668
+ const onSuccess = vi.fn();
669
+ const onSuccessMutate = vi.fn();
670
+ const onSettled = vi.fn();
671
+ const onSettledMutate = vi.fn();
671
672
  const mutationKey = queryKey();
672
673
  let count = 0;
673
674
  function Page() {
@@ -718,10 +719,10 @@ describe('createMutation', () => {
718
719
  expect(onSettledMutate).toHaveBeenCalledTimes(0);
719
720
  });
720
721
  it('should call mutate callbacks only for the last observer', async () => {
721
- const onSuccess = jest.fn();
722
- const onSuccessMutate = jest.fn();
723
- const onSettled = jest.fn();
724
- const onSettledMutate = jest.fn();
722
+ const onSuccess = vi.fn();
723
+ const onSuccessMutate = vi.fn();
724
+ const onSettled = vi.fn();
725
+ const onSettledMutate = vi.fn();
725
726
  let count = 0;
726
727
  function Page() {
727
728
  const mutation = createMutation(() => ({
@@ -762,7 +763,7 @@ describe('createMutation', () => {
762
763
  });
763
764
  it('should go to error state if onSuccess callback errors', async () => {
764
765
  const error = new Error('error from onSuccess');
765
- const onError = jest.fn();
766
+ const onError = vi.fn();
766
767
  function Page() {
767
768
  const mutation = createMutation(() => ({
768
769
  mutationFn: async (_text) => {
@@ -815,7 +816,7 @@ describe('createMutation', () => {
815
816
  it('should go to error state if onSettled callback errors', async () => {
816
817
  const error = new Error('error from onSettled');
817
818
  const mutateFnError = new Error('mutateFnError');
818
- const onError = jest.fn();
819
+ const onError = vi.fn();
819
820
  function Page() {
820
821
  const mutation = createMutation(() => ({
821
822
  mutationFn: async (_text) => {
@@ -3,6 +3,7 @@ import * as QueriesObserverModule from '../../../query-core/src/queriesObserver'
3
3
  import { createRenderEffect, createSignal } from 'solid-js';
4
4
  import { createQueries, QueriesObserver, QueryCache, QueryClientProvider, } from '..';
5
5
  import { createQueryClient, expectType, expectTypeNotAny, queryKey, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('useQueries', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const queryClient = createQueryClient({ queryCache });
@@ -620,7 +621,7 @@ describe('useQueries', () => {
620
621
  return () => void 0;
621
622
  }
622
623
  }
623
- const QueriesObserverSpy = jest
624
+ const QueriesObserverSpy = vi
624
625
  .spyOn(QueriesObserverModule, 'QueriesObserver')
625
626
  .mockImplementation((fn) => {
626
627
  return new QueriesObserverMock(fn);
@@ -657,21 +658,4 @@ describe('useQueries', () => {
657
658
  await sleep(20);
658
659
  QueriesObserverSpy.mockRestore();
659
660
  });
660
- it('should use provided custom queryClient', async () => {
661
- const key = queryKey();
662
- const queryFn = () => {
663
- return Promise.resolve('custom client');
664
- };
665
- function Page() {
666
- const state = createQueries(() => ({
667
- queries: [{ queryKey: key, queryFn }],
668
- queryClient,
669
- }));
670
- return (<div>
671
- <h1>Status: {state[0].data}</h1>
672
- </div>);
673
- }
674
- render(() => <Page />);
675
- await waitFor(() => screen.getByText('Status: custom client'));
676
- });
677
661
  });
@@ -3,6 +3,7 @@ import { createEffect, createMemo, createRenderEffect, createSignal, ErrorBounda
3
3
  import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
4
4
  import { createQuery, QueryCache, QueryClientProvider, keepPreviousData, } from '..';
5
5
  import { Blink, createQueryClient, expectType, mockNavigatorOnLine, mockVisibilityState, queryKey, setActTimeout, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('createQuery', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const queryClient = createQueryClient({ queryCache });
@@ -361,7 +362,7 @@ describe('createQuery', () => {
361
362
  it('should call onSuccess after a query has been fetched', async () => {
362
363
  const key = queryKey();
363
364
  const states = [];
364
- const onSuccess = jest.fn();
365
+ const onSuccess = vi.fn();
365
366
  function Page() {
366
367
  const state = createQuery(() => ({
367
368
  queryKey: key,
@@ -387,7 +388,7 @@ describe('createQuery', () => {
387
388
  it('should call onSuccess after a disabled query has been fetched', async () => {
388
389
  const key = queryKey();
389
390
  const states = [];
390
- const onSuccess = jest.fn();
391
+ const onSuccess = vi.fn();
391
392
  function Page() {
392
393
  const state = createQuery(() => ({
393
394
  queryKey: key,
@@ -416,7 +417,7 @@ describe('createQuery', () => {
416
417
  it('should not call onSuccess if a component has unmounted', async () => {
417
418
  const key = queryKey();
418
419
  const states = [];
419
- const onSuccess = jest.fn();
420
+ const onSuccess = vi.fn();
420
421
  function Page() {
421
422
  const [show, setShow] = createSignal(true);
422
423
  createEffect(() => {
@@ -448,7 +449,7 @@ describe('createQuery', () => {
448
449
  it('should call onError after a query has been fetched with an error', async () => {
449
450
  const key = queryKey();
450
451
  const states = [];
451
- const onError = jest.fn();
452
+ const onError = vi.fn();
452
453
  function Page() {
453
454
  const state = createQuery(() => ({
454
455
  queryKey: key,
@@ -471,7 +472,7 @@ describe('createQuery', () => {
471
472
  });
472
473
  it('should not call onError when receiving a CancelledError', async () => {
473
474
  const key = queryKey();
474
- const onError = jest.fn();
475
+ const onError = vi.fn();
475
476
  function Page() {
476
477
  const state = createQuery(() => ({
477
478
  queryKey: key,
@@ -497,7 +498,7 @@ describe('createQuery', () => {
497
498
  it('should call onSettled after a query has been fetched', async () => {
498
499
  const key = queryKey();
499
500
  const states = [];
500
- const onSettled = jest.fn();
501
+ const onSettled = vi.fn();
501
502
  function Page() {
502
503
  const state = createQuery(() => ({
503
504
  queryKey: key,
@@ -520,7 +521,7 @@ describe('createQuery', () => {
520
521
  it('should call onSettled after a query has been fetched with an error', async () => {
521
522
  const key = queryKey();
522
523
  const states = [];
523
- const onSettled = jest.fn();
524
+ const onSettled = vi.fn();
524
525
  function Page() {
525
526
  const state = createQuery(() => ({
526
527
  queryKey: key,
@@ -1887,7 +1888,7 @@ describe('createQuery', () => {
1887
1888
  });
1888
1889
  it('should not refetch query on focus when `enabled` is set to `false`', async () => {
1889
1890
  const key = queryKey();
1890
- const queryFn = jest.fn().mockReturnValue('data');
1891
+ const queryFn = vi.fn().mockReturnValue('data');
1891
1892
  function Page() {
1892
1893
  const { data = 'default' } = createQuery(() => ({
1893
1894
  queryKey: key,
@@ -2523,7 +2524,7 @@ describe('createQuery', () => {
2523
2524
  });
2524
2525
  it('should retry specified number of times', async () => {
2525
2526
  const key = queryKey();
2526
- const queryFn = jest.fn();
2527
+ const queryFn = vi.fn();
2527
2528
  queryFn.mockImplementation(() => {
2528
2529
  return Promise.reject(new Error('Error test Barrett'));
2529
2530
  });
@@ -2552,7 +2553,7 @@ describe('createQuery', () => {
2552
2553
  });
2553
2554
  it('should not retry if retry function `false`', async () => {
2554
2555
  const key = queryKey();
2555
- const queryFn = jest.fn();
2556
+ const queryFn = vi.fn();
2556
2557
  queryFn.mockImplementationOnce(() => {
2557
2558
  return Promise.reject(new Error('Error test Tanner'));
2558
2559
  });
@@ -2585,7 +2586,7 @@ describe('createQuery', () => {
2585
2586
  });
2586
2587
  it('should extract retryDelay from error', async () => {
2587
2588
  const key = queryKey();
2588
- const queryFn = jest.fn();
2589
+ const queryFn = vi.fn();
2589
2590
  queryFn.mockImplementation(() => {
2590
2591
  return Promise.reject({ delay: 50 });
2591
2592
  });
@@ -2747,9 +2748,9 @@ describe('createQuery', () => {
2747
2748
  it('should refetch if stale after a prefetch', async () => {
2748
2749
  const key = queryKey();
2749
2750
  const states = [];
2750
- const queryFn = jest.fn();
2751
+ const queryFn = vi.fn();
2751
2752
  queryFn.mockImplementation(() => 'data');
2752
- const prefetchQueryFn = jest.fn();
2753
+ const prefetchQueryFn = vi.fn();
2753
2754
  prefetchQueryFn.mockImplementation(() => 'not yet...');
2754
2755
  await queryClient.prefetchQuery({
2755
2756
  queryKey: key,
@@ -2773,9 +2774,9 @@ describe('createQuery', () => {
2773
2774
  });
2774
2775
  it('should not refetch if not stale after a prefetch', async () => {
2775
2776
  const key = queryKey();
2776
- const queryFn = jest.fn();
2777
+ const queryFn = vi.fn();
2777
2778
  queryFn.mockImplementation(() => 'data');
2778
- const prefetchQueryFn = jest.fn();
2779
+ const prefetchQueryFn = vi.fn();
2779
2780
  prefetchQueryFn.mockImplementation(async () => {
2780
2781
  await sleep(10);
2781
2782
  return 'not yet...';
@@ -2977,7 +2978,7 @@ describe('createQuery', () => {
2977
2978
  });
2978
2979
  it('it should support enabled:false in query object syntax', async () => {
2979
2980
  const key = queryKey();
2980
- const queryFn = jest.fn();
2981
+ const queryFn = vi.fn();
2981
2982
  queryFn.mockImplementation(() => 'data');
2982
2983
  function Page() {
2983
2984
  const { fetchStatus } = createQuery(() => ({
@@ -3028,7 +3029,7 @@ describe('createQuery', () => {
3028
3029
  <Page />
3029
3030
  </QueryClientProvider>));
3030
3031
  await waitFor(() => screen.getByText('fetched data'));
3031
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout');
3032
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
3032
3033
  result.unmount();
3033
3034
  expect(setTimeoutSpy).not.toHaveBeenCalled();
3034
3035
  });
@@ -3046,14 +3047,14 @@ describe('createQuery', () => {
3046
3047
  <Page />
3047
3048
  </QueryClientProvider>));
3048
3049
  await waitFor(() => screen.getByText('fetched data'));
3049
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout');
3050
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
3050
3051
  result.unmount();
3051
3052
  expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 1000 * 60 * 10);
3052
3053
  });
3053
3054
  it('should not cause memo churn when data does not change', async () => {
3054
3055
  const key = queryKey();
3055
- const queryFn = jest.fn().mockReturnValue('data');
3056
- const memoFn = jest.fn();
3056
+ const queryFn = vi.fn().mockReturnValue('data');
3057
+ const memoFn = vi.fn();
3057
3058
  function Page() {
3058
3059
  const result = createQuery(() => ({
3059
3060
  queryKey: key,
@@ -3234,7 +3235,7 @@ describe('createQuery', () => {
3234
3235
  });
3235
3236
  it('should refetch if any query instance becomes enabled', async () => {
3236
3237
  const key = queryKey();
3237
- const queryFn = jest.fn().mockReturnValue('data');
3238
+ const queryFn = vi.fn().mockReturnValue('data');
3238
3239
  function Disabled() {
3239
3240
  createQuery(() => ({ queryKey: key, queryFn, enabled: false }));
3240
3241
  return null;
@@ -3504,10 +3505,10 @@ describe('createQuery', () => {
3504
3505
  });
3505
3506
  it('should cancel the query function when there are no more subscriptions', async () => {
3506
3507
  const key = queryKey();
3507
- let cancelFn = jest.fn();
3508
+ let cancelFn = vi.fn();
3508
3509
  const queryFn = ({ signal }) => {
3509
3510
  const promise = new Promise((resolve, reject) => {
3510
- cancelFn = jest.fn(() => reject('Cancelled'));
3511
+ cancelFn = vi.fn(() => reject('Cancelled'));
3511
3512
  signal?.addEventListener('abort', cancelFn);
3512
3513
  sleep(20).then(() => resolve('OK'));
3513
3514
  });
@@ -3767,7 +3768,7 @@ describe('createQuery', () => {
3767
3768
  expect(renders).toBe(hashes);
3768
3769
  });
3769
3770
  it('should refetch when changed enabled to true in error state', async () => {
3770
- const queryFn = jest.fn();
3771
+ const queryFn = vi.fn();
3771
3772
  queryFn.mockImplementation(async () => {
3772
3773
  await sleep(10);
3773
3774
  return Promise.reject(new Error('Suspense Error Bingo'));
@@ -4514,7 +4515,7 @@ describe('createQuery', () => {
4514
4515
  });
4515
4516
  it('setQueryData - should not call onSuccess callback of active observers', async () => {
4516
4517
  const key = queryKey();
4517
- const onSuccess = jest.fn();
4518
+ const onSuccess = vi.fn();
4518
4519
  function Page() {
4519
4520
  const state = createQuery(() => ({
4520
4521
  queryKey: key,
@@ -2,6 +2,7 @@ import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
2
2
  import { createRenderEffect, createSignal, ErrorBoundary, on, Show, Suspense, } from 'solid-js';
3
3
  import { createInfiniteQuery, createQuery, QueryCache, QueryClientProvider, } from '..';
4
4
  import { createQueryClient, queryKey, sleep } from './utils';
5
+ import { vi } from 'vitest';
5
6
  describe("useQuery's in Suspense mode", () => {
6
7
  const queryCache = new QueryCache();
7
8
  const queryClient = createQueryClient({ queryCache });
@@ -91,7 +92,7 @@ describe("useQuery's in Suspense mode", () => {
91
92
  });
92
93
  it('should not call the queryFn twice when used in Suspense mode', async () => {
93
94
  const key = queryKey();
94
- const queryFn = jest.fn();
95
+ const queryFn = vi.fn();
95
96
  queryFn.mockImplementation(() => {
96
97
  sleep(10);
97
98
  return 'data';
@@ -141,7 +142,7 @@ describe("useQuery's in Suspense mode", () => {
141
142
  });
142
143
  it('should call onSuccess on the first successful call', async () => {
143
144
  const key = queryKey();
144
- const successFn = jest.fn();
145
+ const successFn = vi.fn();
145
146
  function Page() {
146
147
  createQuery(() => ({
147
148
  queryKey: [key],
@@ -166,8 +167,8 @@ describe("useQuery's in Suspense mode", () => {
166
167
  });
167
168
  it('should call every onSuccess handler within a suspense boundary', async () => {
168
169
  const key = queryKey();
169
- const successFn1 = jest.fn();
170
- const successFn2 = jest.fn();
170
+ const successFn1 = vi.fn();
171
+ const successFn2 = vi.fn();
171
172
  function FirstComponent() {
172
173
  createQuery(() => ({
173
174
  queryKey: key,
@@ -514,7 +515,7 @@ describe("useQuery's in Suspense mode", () => {
514
515
  });
515
516
  it('should not call the queryFn when not enabled', async () => {
516
517
  const key = queryKey();
517
- const queryFn = jest.fn();
518
+ const queryFn = vi.fn();
518
519
  queryFn.mockImplementation(async () => {
519
520
  await sleep(10);
520
521
  return '23';
@@ -120,9 +120,7 @@ describe('useIsFetching', () => {
120
120
  function Page() {
121
121
  const [started, setStarted] = createSignal(false);
122
122
  const isFetching = useIsFetching(() => ({
123
- filters: {
124
- queryKey: key1,
125
- },
123
+ queryKey: key1,
126
124
  }));
127
125
  createRenderEffect(() => {
128
126
  isFetchings.push(isFetching());
@@ -181,7 +179,7 @@ describe('useIsFetching', () => {
181
179
  return 'test';
182
180
  },
183
181
  }), () => queryClient);
184
- const isFetching = useIsFetching(() => ({ queryClient }));
182
+ const isFetching = useIsFetching(undefined, () => queryClient);
185
183
  return (<div>
186
184
  <div>isFetching: {isFetching}</div>
187
185
  </div>);
@@ -5,6 +5,7 @@ import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js';
5
5
  import { render } from 'solid-testing-library';
6
6
  import * as MutationCacheModule from '../../../query-core/src/mutationCache';
7
7
  import { setActTimeout } from './utils';
8
+ import { vi } from 'vitest';
8
9
  describe('useIsMutating', () => {
9
10
  it('should return the number of fetching mutations', async () => {
10
11
  const isMutatings = [];
@@ -54,9 +55,7 @@ describe('useIsMutating', () => {
54
55
  const isMutatings = [];
55
56
  const queryClient = createQueryClient();
56
57
  function IsMutating() {
57
- const isMutating = useIsMutating(() => ({
58
- filters: { mutationKey: ['mutation1'] },
59
- }));
58
+ const isMutating = useIsMutating(() => ({ mutationKey: ['mutation1'] }));
60
59
  createRenderEffect(() => {
61
60
  isMutatings.push(isMutating());
62
61
  });
@@ -94,9 +93,7 @@ describe('useIsMutating', () => {
94
93
  const queryClient = createQueryClient();
95
94
  function IsMutating() {
96
95
  const isMutating = useIsMutating(() => ({
97
- filters: {
98
- predicate: (mutation) => mutation.options.mutationKey?.[0] === 'mutation1',
99
- },
96
+ predicate: (mutation) => mutation.options.mutationKey?.[0] === 'mutation1',
100
97
  }));
101
98
  createRenderEffect(() => {
102
99
  isMutatings.push(isMutating());
@@ -130,6 +127,27 @@ describe('useIsMutating', () => {
130
127
  // Again, No unnecessary re-renders like React
131
128
  await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]));
132
129
  });
130
+ it('should use provided custom queryClient', async () => {
131
+ const queryClient = createQueryClient();
132
+ function Page() {
133
+ const isMutating = useIsMutating(undefined, () => queryClient);
134
+ const { mutate } = createMutation(() => ({
135
+ mutationKey: ['mutation1'],
136
+ mutationFn: async () => {
137
+ await sleep(10);
138
+ return 'data';
139
+ },
140
+ }), () => queryClient);
141
+ createEffect(() => {
142
+ mutate();
143
+ });
144
+ return (<div>
145
+ <div>mutating: {isMutating}</div>
146
+ </div>);
147
+ }
148
+ render(() => <Page></Page>);
149
+ await waitFor(() => screen.findByText('mutating: 1'));
150
+ });
133
151
  it('should not change state if unmounted', async () => {
134
152
  // We have to mock the MutationCache to not unsubscribe
135
153
  // the listener when the component is unmounted
@@ -139,7 +157,7 @@ describe('useIsMutating', () => {
139
157
  return () => void 0;
140
158
  }
141
159
  }
142
- const MutationCacheSpy = jest
160
+ const MutationCacheSpy = vi
143
161
  .spyOn(MutationCacheModule, 'MutationCache')
144
162
  .mockImplementation((fn) => {
145
163
  return new MutationCacheMock(fn);
@@ -177,25 +195,4 @@ describe('useIsMutating', () => {
177
195
  await sleep(20);
178
196
  MutationCacheSpy.mockRestore();
179
197
  });
180
- it('should use provided custom queryClient', async () => {
181
- const queryClient = createQueryClient();
182
- function Page() {
183
- const isMutating = useIsMutating(() => ({ queryClient }));
184
- const { mutate } = createMutation(() => ({
185
- mutationKey: ['mutation1'],
186
- mutationFn: async () => {
187
- await sleep(10);
188
- return 'data';
189
- },
190
- }), () => queryClient);
191
- createEffect(() => {
192
- mutate();
193
- });
194
- return (<div>
195
- <div>mutating: {isMutating}</div>
196
- </div>);
197
- }
198
- render(() => <Page></Page>);
199
- await waitFor(() => screen.findByText('mutating: 1'));
200
- });
201
198
  });
@@ -1,5 +1,6 @@
1
1
  import { QueryClient } from '@tanstack/query-core';
2
2
  import { createEffect, createSignal, onCleanup, Show } from 'solid-js';
3
+ import { vi } from 'vitest';
3
4
  let queryKeyCount = 0;
4
5
  export function queryKey() {
5
6
  queryKeyCount++;
@@ -20,10 +21,10 @@ export function createQueryClient(config) {
20
21
  return new QueryClient(config);
21
22
  }
22
23
  export function mockVisibilityState(value) {
23
- return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
24
+ return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
24
25
  }
25
26
  export function mockNavigatorOnLine(value) {
26
- return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
27
+ return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
27
28
  }
28
29
  export function sleep(timeout) {
29
30
  return new Promise((resolve, _reject) => {
@@ -2,14 +2,14 @@ import { notifyManager, QueriesObserver } from '@tanstack/query-core';
2
2
  import { createComputed, onCleanup, onMount } from 'solid-js';
3
3
  import { createStore, unwrap } from 'solid-js/store';
4
4
  import { useQueryClient } from './QueryClientProvider';
5
- export function createQueries(queriesOptions) {
6
- const queryClient = useQueryClient(queriesOptions().queryClient);
5
+ export function createQueries(queriesOptions, queryClient) {
6
+ const client = useQueryClient(queryClient?.());
7
7
  const defaultedQueries = queriesOptions().queries.map((options) => {
8
- const defaultedOptions = queryClient.defaultQueryOptions(options);
8
+ const defaultedOptions = client.defaultQueryOptions(options);
9
9
  defaultedOptions._optimisticResults = 'optimistic';
10
10
  return defaultedOptions;
11
11
  });
12
- const observer = new QueriesObserver(queryClient, defaultedQueries);
12
+ const observer = new QueriesObserver(client, defaultedQueries);
13
13
  const [state, setState] = createStore(observer.getOptimisticResult(defaultedQueries));
14
14
  const unsubscribe = observer.subscribe((result) => {
15
15
  notifyManager.batchCalls(() => {
@@ -22,7 +22,7 @@ export function createQueries(queriesOptions) {
22
22
  });
23
23
  createComputed(() => {
24
24
  const updatedQueries = queriesOptions().queries.map((options) => {
25
- const defaultedOptions = queryClient.defaultQueryOptions(options);
25
+ const defaultedOptions = client.defaultQueryOptions(options);
26
26
  defaultedOptions._optimisticResults = 'optimistic';
27
27
  return defaultedOptions;
28
28
  });
@@ -1,11 +1,11 @@
1
1
  import { createMemo, createSignal, onCleanup } from 'solid-js';
2
2
  import { useQueryClient } from './QueryClientProvider';
3
- export function useIsFetching(options = () => ({})) {
4
- const queryClient = createMemo(() => useQueryClient(options().queryClient));
5
- const queryCache = createMemo(() => queryClient().getQueryCache());
6
- const [fetches, setFetches] = createSignal(queryClient().isFetching(options().filters));
3
+ export function useIsFetching(filters, queryClient) {
4
+ const client = createMemo(() => useQueryClient(queryClient?.()));
5
+ const queryCache = createMemo(() => client().getQueryCache());
6
+ const [fetches, setFetches] = createSignal(client().isFetching(filters?.()));
7
7
  const unsubscribe = queryCache().subscribe(() => {
8
- setFetches(queryClient().isFetching(options().filters));
8
+ setFetches(client().isFetching(filters?.()));
9
9
  });
10
10
  onCleanup(unsubscribe);
11
11
  return fetches;
@@ -1,11 +1,11 @@
1
1
  import { useQueryClient } from './QueryClientProvider';
2
2
  import { createSignal, onCleanup, createMemo } from 'solid-js';
3
- export function useIsMutating(options = () => ({})) {
4
- const queryClient = createMemo(() => useQueryClient(options().queryClient));
5
- const mutationCache = createMemo(() => queryClient().getMutationCache());
6
- const [mutations, setMutations] = createSignal(queryClient().isMutating(options().filters));
3
+ export function useIsMutating(filters, queryClient) {
4
+ const client = createMemo(() => useQueryClient(queryClient?.()));
5
+ const mutationCache = createMemo(() => client().getMutationCache());
6
+ const [mutations, setMutations] = createSignal(client().isMutating(filters?.()));
7
7
  const unsubscribe = mutationCache().subscribe((_result) => {
8
- setMutations(queryClient().isMutating(options().filters));
8
+ setMutations(client().isMutating(filters?.()));
9
9
  });
10
10
  onCleanup(unsubscribe);
11
11
  return mutations;
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  /// <reference types="node" />
3
2
  import type { QueryClientConfig } from '@tanstack/query-core';
4
3
  import { QueryClient } from '@tanstack/query-core';
@@ -8,8 +7,8 @@ export declare const Blink: (props: {
8
7
  duration: number;
9
8
  } & ParentProps) => import("solid-js").JSX.Element;
10
9
  export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
11
- export declare function mockVisibilityState(value: DocumentVisibilityState): jest.SpyInstance<DocumentVisibilityState, [], any>;
12
- export declare function mockNavigatorOnLine(value: boolean): jest.SpyInstance<boolean, [], any>;
10
+ export declare function mockVisibilityState(value: DocumentVisibilityState): import("vitest/dist/index-1cfc7f58").S<[], DocumentVisibilityState>;
11
+ export declare function mockNavigatorOnLine(value: boolean): import("vitest/dist/index-1cfc7f58").S<[], boolean>;
13
12
  export declare function sleep(timeout: number): Promise<void>;
14
13
  export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
15
14
  /**
@@ -1,4 +1,4 @@
1
1
  import type { QueryClient, QueryKey, QueryObserver, QueryObserverResult } from '@tanstack/query-core';
2
2
  import type { Accessor } from 'solid-js';
3
3
  import type { CreateBaseQueryOptions } from './types';
4
- export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: Accessor<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, Observer: typeof QueryObserver, queryClient?: () => QueryClient): QueryObserverResult<TData, TError>;
4
+ export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: Accessor<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, Observer: typeof QueryObserver, queryClient?: Accessor<QueryClient>): QueryObserverResult<TData, TError>;
@@ -1,3 +1,4 @@
1
1
  import type { QueryKey, QueryClient, DefaultError, InfiniteData } from '@tanstack/query-core';
2
2
  import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult } from './types';
3
- export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: () => QueryClient): CreateInfiniteQueryResult<TData, TError>;
3
+ import type { Accessor } from 'solid-js';
4
+ export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
@@ -1,3 +1,4 @@
1
1
  import type { QueryClient, DefaultError } from '@tanstack/query-core';
2
2
  import type { CreateMutationOptions, CreateMutationResult } from './types';
3
- export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: CreateMutationOptions<TData, TError, TVariables, TContext>, queryClient?: () => QueryClient): CreateMutationResult<TData, TError, TVariables, TContext>;
3
+ import type { Accessor } from 'solid-js';
4
+ export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: CreateMutationOptions<TData, TError, TVariables, TContext>, queryClient?: Accessor<QueryClient>): CreateMutationResult<TData, TError, TVariables, TContext>;
@@ -1,4 +1,5 @@
1
1
  import type { QueriesPlaceholderDataFunction, QueryClient, QueryFunction, QueryKey, DefaultError } from '@tanstack/query-core';
2
+ import type { Accessor } from 'solid-js';
2
3
  import type { CreateQueryResult, SolidQueryOptions } from './types';
3
4
  declare type CreateQueryOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'placeholderData'> & {
4
5
  placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
@@ -44,8 +45,7 @@ export declare type QueriesOptions<T extends any[], Result extends any[] = [], D
44
45
  * QueriesResults reducer recursively maps type param to results
45
46
  */
46
47
  export declare type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? CreateQueryResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>[] ? CreateQueryResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>[] : CreateQueryResult[];
47
- export declare function createQueries<T extends any[]>(queriesOptions: () => {
48
+ export declare function createQueries<T extends any[]>(queriesOptions: Accessor<{
48
49
  queries: readonly [...QueriesOptions<T>];
49
- queryClient?: QueryClient;
50
- }): QueriesResults<T>;
50
+ }>, queryClient?: Accessor<QueryClient>): QueriesResults<T>;
51
51
  export {};