Skip to content

Commit dfa6ad5

Browse files
committed
fix: sharing enabled field from default query options
1 parent 3c1665c commit dfa6ad5

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/mobx-inifinite-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class MobxInfiniteQuery<
110110
makeObservable(this);
111111

112112
this.options = this.createOptions({
113+
...(this.queryClient.getDefaultOptions().queries as any),
113114
...restOptions,
114115
...config.options?.(this),
115116
});

src/mobx-query.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { describe, expect, it, test, vi } from 'vitest';
1313
import { waitAsync } from 'yammies/async';
1414

1515
import { MobxQuery } from './mobx-query';
16+
import { MobxQueryClient } from './mobx-query-client';
1617
import {
1718
MobxQueryConfig,
1819
MobxQueryDynamicOptions,
@@ -39,10 +40,11 @@ class MobxQueryMock<
3940

4041
constructor(
4142
options: Omit<MobxQueryConfig<TData, TError, TQueryKey>, 'queryClient'>,
43+
queryClient?: QueryClient,
4244
) {
4345
super({
4446
...options,
45-
queryClient: new QueryClient({}),
47+
queryClient: queryClient ?? new QueryClient({}),
4648
// @ts-ignore
4749
queryFn: vi.fn((...args: any[]) => {
4850
// @ts-ignore
@@ -195,6 +197,27 @@ describe('MobxQuery', () => {
195197
});
196198

197199
describe('"enabled" reactive parameter', () => {
200+
it('should work', async () => {
201+
const queryClient = new MobxQueryClient({
202+
defaultOptions: {
203+
queries: {
204+
enabled: false,
205+
},
206+
},
207+
});
208+
const mobxQuery = new MobxQueryMock(
209+
{
210+
queryKey: ['test', 0 as number] as const,
211+
queryFn: () => 100,
212+
},
213+
queryClient,
214+
);
215+
216+
expect(mobxQuery.spies.queryFn).toBeCalledTimes(0);
217+
218+
mobxQuery.dispose();
219+
});
220+
198221
it('should be reactive after change queryKey', async () => {
199222
const mobxQuery = new MobxQueryMock({
200223
queryKey: ['test', 0 as number] as const,

src/mobx-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class MobxQuery<
8686
makeObservable(this);
8787

8888
this.options = this.createOptions({
89+
...(this.queryClient.getDefaultOptions().queries as any),
8990
...restOptions,
9091
...config.options?.(this),
9192
});

0 commit comments

Comments
 (0)