Skip to content

Commit 97f9625

Browse files
types(vue-query): add shallow support to QueryClientConfig (#8692)
Co-authored-by: Damian Osipiuk <[email protected]>
1 parent d4f4956 commit 97f9625

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

packages/vue-query/src/queryClient.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { QueryClient as QC } from '@tanstack/query-core'
33
import { cloneDeepUnref } from './utils'
44
import { QueryCache } from './queryCache'
55
import { MutationCache } from './mutationCache'
6+
import type { UseQueryOptions } from './useQuery'
7+
import type { Ref } from 'vue-demi'
8+
import type { MaybeRefDeep, NoUnknown, QueryClientConfig } from './types'
69
import type {
710
CancelOptions,
811
DefaultError,
@@ -20,7 +23,6 @@ import type {
2023
MutationObserverOptions,
2124
NoInfer,
2225
OmitKeyof,
23-
QueryClientConfig,
2426
QueryFilters,
2527
QueryKey,
2628
QueryObserverOptions,
@@ -31,9 +33,6 @@ import type {
3133
SetDataOptions,
3234
Updater,
3335
} from '@tanstack/query-core'
34-
import type { UseQueryOptions } from './useQuery'
35-
import type { Ref } from 'vue-demi'
36-
import type { MaybeRefDeep, NoUnknown } from './types'
3736

3837
export class QueryClient extends QC {
3938
constructor(config: QueryClientConfig = {}) {

packages/vue-query/src/types.ts

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import type {
2+
DefaultError,
3+
DehydrateOptions,
4+
HydrateOptions,
5+
MutationCache,
6+
MutationObserverOptions,
7+
OmitKeyof,
8+
QueryCache,
9+
QueryObserverOptions,
10+
} from '@tanstack/query-core'
111
import type { ComputedRef, Ref, UnwrapRef } from 'vue-demi'
212

313
type Primitive = string | number | boolean | bigint | symbol | undefined | null
@@ -48,3 +58,29 @@ export type DeepUnwrapRef<T> = T extends UnwrapLeaf
4858
export type DistributiveOmit<T, TKeyOfAny extends keyof any> = T extends any
4959
? Omit<T, TKeyOfAny>
5060
: never
61+
62+
export interface DefaultOptions<TError = DefaultError> {
63+
queries?: OmitKeyof<
64+
QueryObserverOptions<unknown, TError>,
65+
'queryKey' | 'queryFn'
66+
> & {
67+
/**
68+
* Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
69+
*/
70+
shallow?: boolean
71+
}
72+
mutations?: MutationObserverOptions<unknown, TError, unknown, unknown> & {
73+
/**
74+
* Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
75+
*/
76+
shallow?: boolean
77+
}
78+
hydrate?: HydrateOptions['defaultOptions']
79+
dehydrate?: DehydrateOptions
80+
}
81+
82+
export interface QueryClientConfig {
83+
queryCache?: QueryCache
84+
mutationCache?: MutationCache
85+
defaultOptions?: DefaultOptions
86+
}

packages/vue-query/src/useMutation.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<
2929

3030
type UseMutationOptionsBase<TData, TError, TVariables, TContext> =
3131
MutationObserverOptions<TData, TError, TVariables, TContext> & {
32+
/**
33+
* Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
34+
*/
3235
shallow?: boolean
3336
}
3437

packages/vue-query/src/useQuery.ts

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export type UseQueryOptions<
5151
>[Property]
5252
>
5353
} & {
54+
/**
55+
* Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
56+
*/
5457
shallow?: boolean
5558
}
5659
>

packages/vue-query/src/vueQueryPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isServer } from '@tanstack/query-core'
44
import { QueryClient } from './queryClient'
55
import { getClientKey } from './utils'
66
import { setupDevtools } from './devtools/devtools'
7-
import type { QueryClientConfig } from '@tanstack/query-core'
7+
import type { QueryClientConfig } from './types'
88

99
type ClientPersister = (client: QueryClient) => [() => void, Promise<void>]
1010

0 commit comments

Comments
 (0)