@@ -15,7 +15,7 @@ import {
1515 shouldThrowError ,
1616 updateState ,
1717} from './utils'
18- import type { ToRefs } from 'vue-demi'
18+ import type { ToRef } from 'vue-demi'
1919import type {
2020 QueryFunction ,
2121 QueryKey ,
@@ -31,7 +31,11 @@ export type UseQueryReturnType<
3131 TData ,
3232 TError ,
3333 Result = QueryObserverResult < TData , TError > ,
34- > = ToRefs < Readonly < Result > > & {
34+ > = {
35+ [ K in keyof Result ] : Result [ K ] extends ( ...args : any [ ] ) => any
36+ ? Result [ K ]
37+ : ToRef < Result [ K ] >
38+ } & {
3539 suspense : ( ) => Promise < Result >
3640}
3741
@@ -106,19 +110,23 @@ export function useBaseQuery<
106110 { immediate : true } ,
107111 )
108112
109- watch (
110- defaultedOptions ,
111- ( ) => {
112- observer . setOptions ( defaultedOptions . value )
113- updateState ( state , observer . getCurrentResult ( ) )
114- } ,
115- { flush : 'sync' } ,
116- )
113+ const updater = ( ) => {
114+ observer . setOptions ( defaultedOptions . value )
115+ updateState ( state , observer . getCurrentResult ( ) )
116+ }
117+
118+ watch ( defaultedOptions , updater )
117119
118120 onScopeDispose ( ( ) => {
119121 unsubscribe ( )
120122 } )
121123
124+ // fix #5910
125+ const refetch = ( ...args : Parameters < typeof state [ 'refetch' ] > ) => {
126+ updater ( )
127+ return state . refetch ( ...args )
128+ }
129+
122130 const suspense = ( ) => {
123131 return new Promise < QueryObserverResult < TData , TError > > (
124132 ( resolve , reject ) => {
@@ -166,10 +174,17 @@ export function useBaseQuery<
166174 } ,
167175 )
168176
169- return {
170- ...( toRefs ( readonly ( state ) ) as UseQueryReturnType < TData , TError > ) ,
171- suspense,
177+ const object : any = toRefs ( readonly ( state ) )
178+ for ( const key in state ) {
179+ if ( typeof state [ key as keyof typeof state ] === 'function' ) {
180+ object [ key ] = state [ key as keyof typeof state ]
181+ }
172182 }
183+
184+ object . suspense = suspense
185+ object . refetch = refetch
186+
187+ return object as UseQueryReturnType < TData , TError >
173188}
174189
175190export function parseQueryArgs <
0 commit comments