Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(vue-query): add shallow support to QueryClientConfig #8692

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/vue-query/src/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { QueryCache } from './queryCache'
import { MutationCache } from './mutationCache'
import type { UseQueryOptions } from './useQuery'
import type { Ref } from 'vue-demi'
import type { MaybeRefDeep, NoUnknown } from './types'
import type { MaybeRefDeep, NoUnknown, QueryClientConfig } from './types'
import type {
CancelOptions,
DataTag,
Expand All @@ -22,7 +22,6 @@ import type {
MutationObserverOptions,
NoInfer,
OmitKeyof,
QueryClientConfig,
QueryFilters,
QueryKey,
QueryObserverOptions,
Expand Down
36 changes: 36 additions & 0 deletions packages/vue-query/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import type {
DefaultError,
DehydrateOptions,
HydrateOptions,
MutationCache,
MutationObserverOptions,
OmitKeyof,
QueryCache,
QueryObserverOptions,
} from '@tanstack/query-core'
import type { ComputedRef, Ref, UnwrapRef } from 'vue-demi'

type Primitive = string | number | boolean | bigint | symbol | undefined | null
Expand Down Expand Up @@ -48,3 +58,29 @@ export type DeepUnwrapRef<T> = T extends UnwrapLeaf
export type DistributiveOmit<T, TKeyOfAny extends keyof any> = T extends any
? Omit<T, TKeyOfAny>
: never

export interface DefaultOptions<TError = DefaultError> {
queries?: OmitKeyof<
QueryObserverOptions<unknown, TError>,
'queryKey' | 'queryFn'
> & {
/**
* 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.
*/
shallow?: boolean
}
mutations?: MutationObserverOptions<unknown, TError, unknown, unknown> & {
/**
* 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.
*/
shallow?: boolean
}
hydrate?: HydrateOptions['defaultOptions']
dehydrate?: DehydrateOptions
}

export interface QueryClientConfig {
queryCache?: QueryCache
mutationCache?: MutationCache
defaultOptions?: DefaultOptions
}
3 changes: 3 additions & 0 deletions packages/vue-query/src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<

type UseMutationOptionsBase<TData, TError, TVariables, TContext> =
MutationObserverOptions<TData, TError, TVariables, TContext> & {
/**
* 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.
*/
shallow?: boolean
}

Expand Down
3 changes: 3 additions & 0 deletions packages/vue-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export type UseQueryOptions<
>[Property]
>
} & {
/**
* 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.
*/
shallow?: boolean
}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-query/src/vueQueryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isServer } from '@tanstack/query-core'
import { QueryClient } from './queryClient'
import { getClientKey } from './utils'
import { setupDevtools } from './devtools/devtools'
import type { QueryClientConfig } from '@tanstack/query-core'
import type { QueryClientConfig } from './types'

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

Expand Down
Loading