@tanstack/solid-query 4.35.0 → 4.35.7
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/umd/index.development.js +24 -14
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/build/lib/QueryClientProvider.d.ts.map +0 -1
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +0 -1
- package/build/lib/__tests__/createInfiniteQuery.test.d.ts.map +0 -1
- package/build/lib/__tests__/createMutation.test.d.ts.map +0 -1
- package/build/lib/__tests__/createQueries.test.d.ts.map +0 -1
- package/build/lib/__tests__/createQuery.test.d.ts.map +0 -1
- package/build/lib/__tests__/createQuery.types.test.d.ts.map +0 -1
- package/build/lib/__tests__/suspense.test.d.ts.map +0 -1
- package/build/lib/__tests__/transition.test.d.ts.map +0 -1
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +0 -1
- package/build/lib/__tests__/useIsMutating.test.d.ts.map +0 -1
- package/build/lib/__tests__/utils.d.ts.map +0 -1
- package/build/lib/createBaseQuery.d.ts.map +0 -1
- package/build/lib/createInfiniteQuery.d.ts.map +0 -1
- package/build/lib/createMutation.d.ts.map +0 -1
- package/build/lib/createQueries.d.ts.map +0 -1
- package/build/lib/createQuery.d.ts.map +0 -1
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/types.d.ts.map +0 -1
- package/build/lib/useIsFetching.d.ts.map +0 -1
- package/build/lib/useIsMutating.d.ts.map +0 -1
- package/build/lib/utils.d.ts.map +0 -1
- package/build/solid/QueryClientProvider.jsx +0 -49
- package/build/solid/__tests__/QueryClientProvider.test.jsx +0 -185
- package/build/solid/__tests__/createInfiniteQuery.test.jsx +0 -1458
- package/build/solid/__tests__/createMutation.test.jsx +0 -857
- package/build/solid/__tests__/createQueries.test.jsx +0 -958
- package/build/solid/__tests__/createQuery.test.jsx +0 -4559
- package/build/solid/__tests__/createQuery.types.test.jsx +0 -124
- package/build/solid/__tests__/suspense.test.jsx +0 -691
- package/build/solid/__tests__/transition.test.jsx +0 -39
- package/build/solid/__tests__/useIsFetching.test.jsx +0 -209
- package/build/solid/__tests__/useIsMutating.test.jsx +0 -216
- package/build/solid/__tests__/utils.jsx +0 -55
- package/build/solid/createBaseQuery.js +0 -81
- package/build/solid/createInfiniteQuery.js +0 -16
- package/build/solid/createMutation.js +0 -40
- package/build/solid/createQueries.js +0 -39
- package/build/solid/createQuery.js +0 -16
- package/build/solid/index.js +0 -12
- package/build/solid/types.js +0 -2
- package/build/solid/useIsFetching.js +0 -23
- package/build/solid/useIsMutating.js +0 -16
- package/build/solid/utils.js +0 -45
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
|
|
2
|
-
import { Show, Suspense, createSignal, startTransition } from 'solid-js';
|
|
3
|
-
import { QueryCache, QueryClientProvider, createQuery } from '..';
|
|
4
|
-
import { createQueryClient, queryKey, sleep } from './utils';
|
|
5
|
-
describe("useQuery's in Suspense mode with transitions", () => {
|
|
6
|
-
const queryCache = new QueryCache();
|
|
7
|
-
const queryClient = createQueryClient({ queryCache });
|
|
8
|
-
it('should render the content when the transition is done', async () => {
|
|
9
|
-
const key = queryKey();
|
|
10
|
-
function Suspended() {
|
|
11
|
-
const state = createQuery(key, async () => {
|
|
12
|
-
await sleep(10);
|
|
13
|
-
return true;
|
|
14
|
-
});
|
|
15
|
-
return <Show when={state.data}>Message</Show>;
|
|
16
|
-
}
|
|
17
|
-
function Page() {
|
|
18
|
-
const [showSignal, setShowSignal] = createSignal(false);
|
|
19
|
-
return (<div>
|
|
20
|
-
<button aria-label="toggle" onClick={() => startTransition(() => setShowSignal((value) => !value))}>
|
|
21
|
-
{showSignal() ? 'Hide' : 'Show'}
|
|
22
|
-
</button>
|
|
23
|
-
<Suspense fallback="Loading">
|
|
24
|
-
<Show when={showSignal()}>
|
|
25
|
-
<Suspended />
|
|
26
|
-
</Show>
|
|
27
|
-
</Suspense>
|
|
28
|
-
</div>);
|
|
29
|
-
}
|
|
30
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
31
|
-
<Page />
|
|
32
|
-
</QueryClientProvider>));
|
|
33
|
-
await waitFor(() => screen.getByText('Show'));
|
|
34
|
-
fireEvent.click(screen.getByLabelText('toggle'));
|
|
35
|
-
await waitFor(() => screen.getByText('Message'));
|
|
36
|
-
// verify that the button also updated. See https://github.com/solidjs/solid/issues/1249
|
|
37
|
-
await waitFor(() => screen.getByText('Hide'));
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
|
|
2
|
-
import { ErrorBoundary, Show, createContext, createEffect, createRenderEffect, createSignal, } from 'solid-js';
|
|
3
|
-
import { QueryCache, QueryClientProvider, createQuery, useIsFetching } from '..';
|
|
4
|
-
import { createQueryClient, queryKey, setActTimeout, sleep } from './utils';
|
|
5
|
-
describe('useIsFetching', () => {
|
|
6
|
-
// See https://github.com/tannerlinsley/react-query/issues/105
|
|
7
|
-
it('should update as queries start and stop fetching', async () => {
|
|
8
|
-
const queryCache = new QueryCache();
|
|
9
|
-
const queryClient = createQueryClient({ queryCache });
|
|
10
|
-
const key = queryKey();
|
|
11
|
-
function IsFetching() {
|
|
12
|
-
const isFetching = useIsFetching();
|
|
13
|
-
return <div>isFetching: {isFetching()}</div>;
|
|
14
|
-
}
|
|
15
|
-
function Query() {
|
|
16
|
-
const [ready, setReady] = createSignal(false);
|
|
17
|
-
createQuery(key, async () => {
|
|
18
|
-
await sleep(50);
|
|
19
|
-
return 'test';
|
|
20
|
-
}, {
|
|
21
|
-
get enabled() {
|
|
22
|
-
return ready();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
return <button onClick={() => setReady(true)}>setReady</button>;
|
|
26
|
-
}
|
|
27
|
-
function Page() {
|
|
28
|
-
return (<div>
|
|
29
|
-
<IsFetching />
|
|
30
|
-
<Query />
|
|
31
|
-
</div>);
|
|
32
|
-
}
|
|
33
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
34
|
-
<Page />
|
|
35
|
-
</QueryClientProvider>));
|
|
36
|
-
await screen.findByText('isFetching: 0');
|
|
37
|
-
fireEvent.click(screen.getByRole('button', { name: /setReady/i }));
|
|
38
|
-
await screen.findByText('isFetching: 1');
|
|
39
|
-
await screen.findByText('isFetching: 0');
|
|
40
|
-
});
|
|
41
|
-
it('should not update state while rendering', async () => {
|
|
42
|
-
const queryCache = new QueryCache();
|
|
43
|
-
const queryClient = createQueryClient({ queryCache });
|
|
44
|
-
const key1 = queryKey();
|
|
45
|
-
const key2 = queryKey();
|
|
46
|
-
const isFetchings = [];
|
|
47
|
-
function IsFetching() {
|
|
48
|
-
const isFetching = useIsFetching();
|
|
49
|
-
createRenderEffect(() => {
|
|
50
|
-
isFetchings.push(isFetching());
|
|
51
|
-
});
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
function FirstQuery() {
|
|
55
|
-
createQuery(key1, async () => {
|
|
56
|
-
await sleep(100);
|
|
57
|
-
return 'data';
|
|
58
|
-
});
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
function SecondQuery() {
|
|
62
|
-
createQuery(key2, async () => {
|
|
63
|
-
await sleep(100);
|
|
64
|
-
return 'data';
|
|
65
|
-
});
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
function Page() {
|
|
69
|
-
const [renderSecond, setRenderSecond] = createSignal(false);
|
|
70
|
-
createEffect(() => {
|
|
71
|
-
setActTimeout(() => {
|
|
72
|
-
setRenderSecond(true);
|
|
73
|
-
}, 50);
|
|
74
|
-
});
|
|
75
|
-
return (<>
|
|
76
|
-
<IsFetching />
|
|
77
|
-
<FirstQuery />
|
|
78
|
-
<Show when={renderSecond()}>
|
|
79
|
-
<SecondQuery />
|
|
80
|
-
</Show>
|
|
81
|
-
</>);
|
|
82
|
-
}
|
|
83
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
84
|
-
<Page />
|
|
85
|
-
</QueryClientProvider>));
|
|
86
|
-
// unlike react, Updating renderSecond wont cause a rerender for FirstQuery
|
|
87
|
-
await waitFor(() => expect(isFetchings).toEqual([0, 1, 2, 1, 0]));
|
|
88
|
-
});
|
|
89
|
-
it('should be able to filter', async () => {
|
|
90
|
-
const queryClient = createQueryClient();
|
|
91
|
-
const key1 = queryKey();
|
|
92
|
-
const key2 = queryKey();
|
|
93
|
-
const isFetchings = [];
|
|
94
|
-
function One() {
|
|
95
|
-
createQuery(key1, async () => {
|
|
96
|
-
await sleep(10);
|
|
97
|
-
return 'test';
|
|
98
|
-
});
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
function Two() {
|
|
102
|
-
createQuery(key2, async () => {
|
|
103
|
-
await sleep(20);
|
|
104
|
-
return 'test';
|
|
105
|
-
});
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
function Page() {
|
|
109
|
-
const [started, setStarted] = createSignal(false);
|
|
110
|
-
const isFetching = useIsFetching(key1);
|
|
111
|
-
createRenderEffect(() => {
|
|
112
|
-
isFetchings.push(isFetching());
|
|
113
|
-
});
|
|
114
|
-
return (<div>
|
|
115
|
-
<button onClick={() => setStarted(true)}>setStarted</button>
|
|
116
|
-
<div>isFetching: {isFetching()}</div>
|
|
117
|
-
<Show when={started()}>
|
|
118
|
-
<>
|
|
119
|
-
<One />
|
|
120
|
-
<Two />
|
|
121
|
-
</>
|
|
122
|
-
</Show>
|
|
123
|
-
</div>);
|
|
124
|
-
}
|
|
125
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
126
|
-
<Page />
|
|
127
|
-
</QueryClientProvider>));
|
|
128
|
-
await screen.findByText('isFetching: 0');
|
|
129
|
-
fireEvent.click(screen.getByRole('button', { name: /setStarted/i }));
|
|
130
|
-
await screen.findByText('isFetching: 1');
|
|
131
|
-
await screen.findByText('isFetching: 0');
|
|
132
|
-
// at no point should we have isFetching: 2
|
|
133
|
-
expect(isFetchings).toEqual(expect.not.arrayContaining([2]));
|
|
134
|
-
});
|
|
135
|
-
describe('with custom context', () => {
|
|
136
|
-
it('should update as queries start and stop fetching', async () => {
|
|
137
|
-
const context = createContext(undefined);
|
|
138
|
-
const queryCache = new QueryCache();
|
|
139
|
-
const queryClient = createQueryClient({ queryCache });
|
|
140
|
-
const key = queryKey();
|
|
141
|
-
function Page() {
|
|
142
|
-
const [ready, setReady] = createSignal(false);
|
|
143
|
-
const isFetching = useIsFetching(undefined, { context: context });
|
|
144
|
-
createQuery(key, async () => {
|
|
145
|
-
await sleep(50);
|
|
146
|
-
return 'test';
|
|
147
|
-
}, {
|
|
148
|
-
get enabled() {
|
|
149
|
-
return ready();
|
|
150
|
-
},
|
|
151
|
-
context,
|
|
152
|
-
});
|
|
153
|
-
return (<div>
|
|
154
|
-
<div>isFetching: {isFetching}</div>
|
|
155
|
-
<button onClick={() => setReady(true)}>setReady</button>
|
|
156
|
-
</div>);
|
|
157
|
-
}
|
|
158
|
-
render(() => (<QueryClientProvider client={queryClient} context={context}>
|
|
159
|
-
<Page />
|
|
160
|
-
</QueryClientProvider>));
|
|
161
|
-
await screen.findByText('isFetching: 0');
|
|
162
|
-
fireEvent.click(screen.getByRole('button', { name: /setReady/i }));
|
|
163
|
-
await screen.findByText('isFetching: 1');
|
|
164
|
-
await screen.findByText('isFetching: 0');
|
|
165
|
-
});
|
|
166
|
-
it('should throw if the context is not passed to useIsFetching', async () => {
|
|
167
|
-
const context = createContext(undefined);
|
|
168
|
-
const queryCache = new QueryCache();
|
|
169
|
-
const queryClient = createQueryClient({ queryCache });
|
|
170
|
-
const key = queryKey();
|
|
171
|
-
function Page() {
|
|
172
|
-
const isFetching = useIsFetching();
|
|
173
|
-
createQuery(key, async () => 'test', {
|
|
174
|
-
enabled: true,
|
|
175
|
-
context,
|
|
176
|
-
useErrorBoundary: true,
|
|
177
|
-
});
|
|
178
|
-
return (<div>
|
|
179
|
-
<div>isFetching: {isFetching}</div>
|
|
180
|
-
</div>);
|
|
181
|
-
}
|
|
182
|
-
render(() => (<QueryClientProvider client={queryClient} context={context}>
|
|
183
|
-
<ErrorBoundary fallback={() => <div>error boundary</div>}>
|
|
184
|
-
<Page />
|
|
185
|
-
</ErrorBoundary>
|
|
186
|
-
</QueryClientProvider>));
|
|
187
|
-
await waitFor(() => screen.getByText('error boundary'));
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
it('should show the correct fetching state when mounted after a query', async () => {
|
|
191
|
-
const queryClient = createQueryClient();
|
|
192
|
-
const key = queryKey();
|
|
193
|
-
function Page() {
|
|
194
|
-
createQuery(key, async () => {
|
|
195
|
-
await sleep(10);
|
|
196
|
-
return 'test';
|
|
197
|
-
});
|
|
198
|
-
const isFetching = useIsFetching();
|
|
199
|
-
return (<div>
|
|
200
|
-
<div>isFetching: {isFetching()}</div>
|
|
201
|
-
</div>);
|
|
202
|
-
}
|
|
203
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
204
|
-
<Page />
|
|
205
|
-
</QueryClientProvider>));
|
|
206
|
-
await screen.findByText('isFetching: 1');
|
|
207
|
-
await screen.findByText('isFetching: 0');
|
|
208
|
-
});
|
|
209
|
-
});
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { fireEvent, screen, waitFor } from 'solid-testing-library';
|
|
2
|
-
import { ErrorBoundary, Show, createContext, createEffect, createRenderEffect, createSignal, } from 'solid-js';
|
|
3
|
-
import { render } from 'solid-testing-library';
|
|
4
|
-
import { QueryClient, QueryClientProvider, createMutation, useIsMutating, } from '..';
|
|
5
|
-
import * as MutationCacheModule from '../../../query-core/src/mutationCache';
|
|
6
|
-
import { createQueryClient, sleep } from './utils';
|
|
7
|
-
import { setActTimeout } from './utils';
|
|
8
|
-
describe('useIsMutating', () => {
|
|
9
|
-
it('should return the number of fetching mutations', async () => {
|
|
10
|
-
const isMutatings = [];
|
|
11
|
-
const queryClient = createQueryClient();
|
|
12
|
-
function IsMutating() {
|
|
13
|
-
const isMutating = useIsMutating();
|
|
14
|
-
createRenderEffect(() => {
|
|
15
|
-
isMutatings.push(isMutating());
|
|
16
|
-
});
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
function Mutations() {
|
|
20
|
-
const { mutate: mutate1 } = createMutation(['mutation1'], async () => {
|
|
21
|
-
await sleep(150);
|
|
22
|
-
return 'data';
|
|
23
|
-
});
|
|
24
|
-
const { mutate: mutate2 } = createMutation(['mutation2'], async () => {
|
|
25
|
-
await sleep(50);
|
|
26
|
-
return 'data';
|
|
27
|
-
});
|
|
28
|
-
createEffect(() => {
|
|
29
|
-
mutate1();
|
|
30
|
-
setActTimeout(() => {
|
|
31
|
-
mutate2();
|
|
32
|
-
}, 50);
|
|
33
|
-
});
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
function Page() {
|
|
37
|
-
return (<div>
|
|
38
|
-
<IsMutating />
|
|
39
|
-
<Mutations />
|
|
40
|
-
</div>);
|
|
41
|
-
}
|
|
42
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
43
|
-
<Page />
|
|
44
|
-
</QueryClientProvider>));
|
|
45
|
-
await waitFor(() => expect(isMutatings).toEqual([0, 1, 2, 1, 0]));
|
|
46
|
-
});
|
|
47
|
-
it('should filter correctly by mutationKey', async () => {
|
|
48
|
-
const isMutatings = [];
|
|
49
|
-
const queryClient = createQueryClient();
|
|
50
|
-
function IsMutating() {
|
|
51
|
-
const isMutating = useIsMutating(['mutation1']);
|
|
52
|
-
createRenderEffect(() => {
|
|
53
|
-
isMutatings.push(isMutating());
|
|
54
|
-
});
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
function Page() {
|
|
58
|
-
const { mutate: mutate1 } = createMutation(['mutation1'], async () => {
|
|
59
|
-
await sleep(100);
|
|
60
|
-
return 'data';
|
|
61
|
-
});
|
|
62
|
-
const { mutate: mutate2 } = createMutation(['mutation2'], async () => {
|
|
63
|
-
await sleep(100);
|
|
64
|
-
return 'data';
|
|
65
|
-
});
|
|
66
|
-
createEffect(() => {
|
|
67
|
-
mutate1();
|
|
68
|
-
mutate2();
|
|
69
|
-
});
|
|
70
|
-
return <IsMutating />;
|
|
71
|
-
}
|
|
72
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
73
|
-
<Page />
|
|
74
|
-
</QueryClientProvider>));
|
|
75
|
-
// Unlike React, IsMutating Wont re-render twice with mutation2
|
|
76
|
-
await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]));
|
|
77
|
-
});
|
|
78
|
-
it('should filter correctly by predicate', async () => {
|
|
79
|
-
const isMutatings = [];
|
|
80
|
-
const queryClient = createQueryClient();
|
|
81
|
-
function IsMutating() {
|
|
82
|
-
const isMutating = useIsMutating({
|
|
83
|
-
predicate: (mutation) => mutation.options.mutationKey?.[0] === 'mutation1',
|
|
84
|
-
});
|
|
85
|
-
createRenderEffect(() => {
|
|
86
|
-
isMutatings.push(isMutating());
|
|
87
|
-
});
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
function Page() {
|
|
91
|
-
const { mutate: mutate1 } = createMutation(['mutation1'], async () => {
|
|
92
|
-
await sleep(100);
|
|
93
|
-
return 'data';
|
|
94
|
-
});
|
|
95
|
-
const { mutate: mutate2 } = createMutation(['mutation2'], async () => {
|
|
96
|
-
await sleep(100);
|
|
97
|
-
return 'data';
|
|
98
|
-
});
|
|
99
|
-
createEffect(() => {
|
|
100
|
-
mutate1();
|
|
101
|
-
mutate2();
|
|
102
|
-
});
|
|
103
|
-
return <IsMutating />;
|
|
104
|
-
}
|
|
105
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
106
|
-
<Page />
|
|
107
|
-
</QueryClientProvider>));
|
|
108
|
-
// Again, No unnecessary re-renders like React
|
|
109
|
-
await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]));
|
|
110
|
-
});
|
|
111
|
-
it('should not change state if unmounted', async () => {
|
|
112
|
-
// We have to mock the MutationCache to not unsubscribe
|
|
113
|
-
// the listener when the component is unmounted
|
|
114
|
-
class MutationCacheMock extends MutationCacheModule.MutationCache {
|
|
115
|
-
subscribe(listener) {
|
|
116
|
-
super.subscribe(listener);
|
|
117
|
-
return () => void 0;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const MutationCacheSpy = jest
|
|
121
|
-
.spyOn(MutationCacheModule, 'MutationCache')
|
|
122
|
-
.mockImplementation((fn) => {
|
|
123
|
-
return new MutationCacheMock(fn);
|
|
124
|
-
});
|
|
125
|
-
const queryClient = createQueryClient();
|
|
126
|
-
function IsMutating() {
|
|
127
|
-
useIsMutating();
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
function Page() {
|
|
131
|
-
const [mounted, setMounted] = createSignal(true);
|
|
132
|
-
const { mutate: mutate1 } = createMutation(['mutation1'], async () => {
|
|
133
|
-
await sleep(10);
|
|
134
|
-
return 'data';
|
|
135
|
-
});
|
|
136
|
-
createEffect(() => {
|
|
137
|
-
mutate1();
|
|
138
|
-
});
|
|
139
|
-
return (<div>
|
|
140
|
-
<button onClick={() => setMounted(false)}>unmount</button>
|
|
141
|
-
<Show when={mounted()}>
|
|
142
|
-
<IsMutating />
|
|
143
|
-
</Show>
|
|
144
|
-
</div>);
|
|
145
|
-
}
|
|
146
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
147
|
-
<Page />
|
|
148
|
-
</QueryClientProvider>));
|
|
149
|
-
fireEvent.click(screen.getByText('unmount'));
|
|
150
|
-
// Should not display the console error
|
|
151
|
-
// "Warning: Can't perform a React state update on an unmounted component"
|
|
152
|
-
await sleep(20);
|
|
153
|
-
MutationCacheSpy.mockRestore();
|
|
154
|
-
});
|
|
155
|
-
describe('with custom context', () => {
|
|
156
|
-
it('should return the number of fetching mutations', async () => {
|
|
157
|
-
const context = createContext(undefined);
|
|
158
|
-
const isMutatings = [];
|
|
159
|
-
const queryClient = new QueryClient();
|
|
160
|
-
function IsMutating() {
|
|
161
|
-
const isMutating = useIsMutating(undefined, { context });
|
|
162
|
-
createRenderEffect(() => {
|
|
163
|
-
isMutatings.push(isMutating());
|
|
164
|
-
});
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
function Page() {
|
|
168
|
-
const { mutate: mutate1 } = createMutation(['mutation1'], async () => {
|
|
169
|
-
await sleep(150);
|
|
170
|
-
return 'data';
|
|
171
|
-
}, { context });
|
|
172
|
-
const { mutate: mutate2 } = createMutation(['mutation2'], async () => {
|
|
173
|
-
await sleep(50);
|
|
174
|
-
return 'data';
|
|
175
|
-
}, { context });
|
|
176
|
-
createEffect(() => {
|
|
177
|
-
mutate1();
|
|
178
|
-
setActTimeout(() => {
|
|
179
|
-
mutate2();
|
|
180
|
-
}, 50);
|
|
181
|
-
});
|
|
182
|
-
return <IsMutating />;
|
|
183
|
-
}
|
|
184
|
-
render(() => (<QueryClientProvider client={queryClient} context={context}>
|
|
185
|
-
<Page />
|
|
186
|
-
</QueryClientProvider>));
|
|
187
|
-
await waitFor(() => expect(isMutatings).toEqual([0, 1, 2, 1, 0]));
|
|
188
|
-
});
|
|
189
|
-
it('should throw if the context is not passed to useIsMutating', async () => {
|
|
190
|
-
const context = createContext(undefined);
|
|
191
|
-
const isMutatings = [];
|
|
192
|
-
const queryClient = new QueryClient();
|
|
193
|
-
function IsMutating() {
|
|
194
|
-
const isMutating = useIsMutating(undefined);
|
|
195
|
-
isMutatings.push(isMutating());
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
function Page() {
|
|
199
|
-
const { mutate } = createMutation(['mutation'], async () => 'data', {
|
|
200
|
-
useErrorBoundary: true,
|
|
201
|
-
context,
|
|
202
|
-
});
|
|
203
|
-
createEffect(() => {
|
|
204
|
-
mutate();
|
|
205
|
-
});
|
|
206
|
-
return <IsMutating />;
|
|
207
|
-
}
|
|
208
|
-
render(() => (<QueryClientProvider client={queryClient} context={context}>
|
|
209
|
-
<ErrorBoundary fallback={() => <div>error boundary</div>}>
|
|
210
|
-
<Page />
|
|
211
|
-
</ErrorBoundary>
|
|
212
|
-
</QueryClientProvider>));
|
|
213
|
-
await waitFor(() => screen.getByText('error boundary'));
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/query-core';
|
|
2
|
-
import { Show, createEffect, createSignal, onCleanup } from 'solid-js';
|
|
3
|
-
let queryKeyCount = 0;
|
|
4
|
-
export function queryKey() {
|
|
5
|
-
const localQueryKeyCount = queryKeyCount++;
|
|
6
|
-
return () => [`query_${localQueryKeyCount}`];
|
|
7
|
-
}
|
|
8
|
-
export const Blink = (props) => {
|
|
9
|
-
const [shouldShow, setShouldShow] = createSignal(true);
|
|
10
|
-
createEffect(() => {
|
|
11
|
-
setShouldShow(true);
|
|
12
|
-
const timeout = setActTimeout(() => setShouldShow(false), props.duration);
|
|
13
|
-
onCleanup(() => clearTimeout(timeout));
|
|
14
|
-
});
|
|
15
|
-
return (<Show when={shouldShow()} fallback={<>off</>}>
|
|
16
|
-
<>{props.children}</>
|
|
17
|
-
</Show>);
|
|
18
|
-
};
|
|
19
|
-
export function createQueryClient(config) {
|
|
20
|
-
jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
21
|
-
return new QueryClient({ logger: mockLogger, ...config });
|
|
22
|
-
}
|
|
23
|
-
export function mockVisibilityState(value) {
|
|
24
|
-
return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
|
|
25
|
-
}
|
|
26
|
-
export function mockNavigatorOnLine(value) {
|
|
27
|
-
return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
|
|
28
|
-
}
|
|
29
|
-
export const mockLogger = {
|
|
30
|
-
log: jest.fn(),
|
|
31
|
-
warn: jest.fn(),
|
|
32
|
-
error: jest.fn(),
|
|
33
|
-
};
|
|
34
|
-
export function sleep(timeout) {
|
|
35
|
-
return new Promise((resolve, _reject) => {
|
|
36
|
-
setTimeout(resolve, timeout);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export function setActTimeout(fn, ms) {
|
|
40
|
-
return setTimeout(() => {
|
|
41
|
-
fn();
|
|
42
|
-
}, ms);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Assert the parameter is of a specific type.
|
|
46
|
-
*/
|
|
47
|
-
export function expectType(_) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Assert the parameter is not typed as `any`
|
|
52
|
-
*/
|
|
53
|
-
export function expectTypeNotAny(_) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { batch, createComputed, createResource, on, onCleanup, onMount, } from 'solid-js';
|
|
2
|
-
import { createStore, unwrap } from 'solid-js/store';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider';
|
|
4
|
-
import { shouldThrowError } from './utils';
|
|
5
|
-
// Base Query Function that is used to create the query.
|
|
6
|
-
export function createBaseQuery(options, Observer) {
|
|
7
|
-
const queryClient = useQueryClient({ context: options.context });
|
|
8
|
-
const emptyData = Symbol('empty');
|
|
9
|
-
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
10
|
-
defaultedOptions._optimisticResults = 'optimistic';
|
|
11
|
-
const observer = new Observer(queryClient, defaultedOptions);
|
|
12
|
-
const [state, setState] = createStore(
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
observer.getOptimisticResult(defaultedOptions));
|
|
15
|
-
const [dataResource, { refetch, mutate }] = createResource(() => {
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
if (!(state.isFetching && state.isLoading)) {
|
|
18
|
-
if (unwrap(state.data) === emptyData) {
|
|
19
|
-
resolve(undefined);
|
|
20
|
-
}
|
|
21
|
-
resolve(unwrap(state.data));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
batch(() => {
|
|
26
|
-
mutate(() => unwrap(state.data));
|
|
27
|
-
refetch();
|
|
28
|
-
});
|
|
29
|
-
let taskQueue = [];
|
|
30
|
-
const unsubscribe = observer.subscribe((result) => {
|
|
31
|
-
taskQueue.push(() => {
|
|
32
|
-
batch(() => {
|
|
33
|
-
const unwrappedResult = { ...unwrap(result) };
|
|
34
|
-
if (unwrappedResult.data === undefined) {
|
|
35
|
-
// This is a hack to prevent Solid
|
|
36
|
-
// from deleting the data property when it is `undefined`
|
|
37
|
-
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
unwrappedResult.data = emptyData;
|
|
40
|
-
}
|
|
41
|
-
setState(unwrap(unwrappedResult));
|
|
42
|
-
mutate(() => unwrap(result.data));
|
|
43
|
-
refetch();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
queueMicrotask(() => {
|
|
47
|
-
const taskToRun = taskQueue.pop();
|
|
48
|
-
if (taskToRun) {
|
|
49
|
-
taskToRun();
|
|
50
|
-
}
|
|
51
|
-
taskQueue = [];
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
onCleanup(() => unsubscribe());
|
|
55
|
-
onMount(() => {
|
|
56
|
-
observer.setOptions(defaultedOptions, { listeners: false });
|
|
57
|
-
});
|
|
58
|
-
createComputed(() => {
|
|
59
|
-
const newDefaultedOptions = queryClient.defaultQueryOptions(options);
|
|
60
|
-
observer.setOptions(newDefaultedOptions);
|
|
61
|
-
});
|
|
62
|
-
createComputed(on(() => state.status, () => {
|
|
63
|
-
if (state.isError &&
|
|
64
|
-
!state.isFetching &&
|
|
65
|
-
shouldThrowError(observer.options.useErrorBoundary, [
|
|
66
|
-
state.error,
|
|
67
|
-
observer.getCurrentQuery(),
|
|
68
|
-
])) {
|
|
69
|
-
throw state.error;
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
const handler = {
|
|
73
|
-
get(target, prop) {
|
|
74
|
-
if (prop === 'data') {
|
|
75
|
-
return dataResource();
|
|
76
|
-
}
|
|
77
|
-
return Reflect.get(target, prop);
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
return new Proxy(state, handler);
|
|
81
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { createComputed } from 'solid-js';
|
|
3
|
-
import { createStore } from 'solid-js/store';
|
|
4
|
-
import { createBaseQuery } from './createBaseQuery';
|
|
5
|
-
import { parseQueryArgs } from './utils';
|
|
6
|
-
export function createInfiniteQuery(arg1, arg2, arg3) {
|
|
7
|
-
// The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
8
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
9
|
-
const [parsedOptions, setParsedOptions] = createStore(parseQueryArgs(arg1, arg2, arg3));
|
|
10
|
-
// Watch for changes in the options and update the parsed options.
|
|
11
|
-
createComputed(() => {
|
|
12
|
-
const newParsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
13
|
-
setParsedOptions(newParsedOptions);
|
|
14
|
-
});
|
|
15
|
-
return createBaseQuery(parsedOptions, InfiniteQueryObserver);
|
|
16
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { MutationObserver, parseMutationArgs } from '@tanstack/query-core';
|
|
2
|
-
import { createComputed, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { createStore } from 'solid-js/store';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider';
|
|
5
|
-
import { shouldThrowError } from './utils';
|
|
6
|
-
export function createMutation(arg1, arg2, arg3) {
|
|
7
|
-
const [options, setOptions] = createStore(parseMutationArgs(arg1, arg2, arg3));
|
|
8
|
-
const queryClient = useQueryClient({ context: options.context });
|
|
9
|
-
const observer = new MutationObserver(queryClient, options);
|
|
10
|
-
const mutate = (variables, mutateOptions) => {
|
|
11
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
12
|
-
};
|
|
13
|
-
const [state, setState] = createStore({
|
|
14
|
-
...observer.getCurrentResult(),
|
|
15
|
-
mutate,
|
|
16
|
-
mutateAsync: observer.getCurrentResult().mutate,
|
|
17
|
-
});
|
|
18
|
-
createComputed(() => {
|
|
19
|
-
const newParsedOptions = parseMutationArgs(arg1, arg2, arg3);
|
|
20
|
-
setOptions(newParsedOptions);
|
|
21
|
-
observer.setOptions(newParsedOptions);
|
|
22
|
-
});
|
|
23
|
-
createComputed(on(() => state.status, () => {
|
|
24
|
-
if (state.isError &&
|
|
25
|
-
shouldThrowError(observer.options.useErrorBoundary, [state.error])) {
|
|
26
|
-
throw state.error;
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
|
-
const unsubscribe = observer.subscribe((result) => {
|
|
30
|
-
setState({
|
|
31
|
-
...result,
|
|
32
|
-
mutate,
|
|
33
|
-
mutateAsync: result.mutate,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
onCleanup(unsubscribe);
|
|
37
|
-
return state;
|
|
38
|
-
}
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
40
|
-
function noop() { }
|