@@ -7,10 +7,10 @@ import type {
77 TypedDocumentNode
88} from '@apollo/client/core'
99import type { DocumentNode } from 'graphql'
10- import type { MaybeRefOrGetter , Ref } from 'vue'
10+ import type { MaybeRefOrGetter } from 'vue'
1111
12- import { createEventHook , syncRef , useDebounceFn , useThrottleFn } from '@vueuse/core'
13- import { computed , getCurrentScope , isReadonly , isRef , onScopeDispose , onServerPrefetch , ref , shallowRef , toValue , watch } from 'vue'
12+ import { createEventHook , useDebounceFn , useThrottleFn } from '@vueuse/core'
13+ import { computed , getCurrentScope , onScopeDispose , onServerPrefetch , ref , shallowRef , toValue , watch } from 'vue'
1414
1515import type { HookContext , UseBaseOption } from '../utils/type'
1616
@@ -164,13 +164,7 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
164164 type : 'queries'
165165 } )
166166
167- const reactiveVariables = ref ( toValue ( variables ) )
168- if ( isRef ( variables ) ) {
169- syncRef ( variables as Ref , reactiveVariables , {
170- direction : isReadonly ( variables ) ? 'ltr' : 'both'
171- } )
172- }
173-
167+ const reactiveVariables = computed ( ( ) => toValue ( variables ) ?? { } as TVariables )
174168 const reactiveDocument = computed ( ( ) => toValue ( document ) )
175169
176170 const getQueryOptions = ( ) => {
@@ -192,7 +186,7 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
192186 const queryResult = await client . query < TData , TVariables > ( {
193187 ...getQueryOptions ( ) ,
194188 query : reactiveDocument . value ,
195- variables : toValue ( reactiveVariables )
189+ variables : reactiveVariables . value
196190 } )
197191
198192 // Set initial data from server
@@ -274,7 +268,7 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
274268 try {
275269 const cachedData = client . readQuery < TData , TVariables > ( {
276270 query : reactiveDocument . value ,
277- variables : toValue ( reactiveVariables )
271+ variables : reactiveVariables . value
278272 } )
279273
280274 // If we have cached data from SSR, set the result and loading state immediately
@@ -289,10 +283,10 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
289283 }
290284
291285 query . value = client . watchQuery < TData , TVariables > ( {
286+ ...getQueryOptions ( ) ,
292287 notifyOnNetworkStatusChange : options ?. notifyOnNetworkStatusChange ?? options ?. keepPreviousResult ,
293288 query : reactiveDocument . value ,
294- variables : toValue ( reactiveVariables ) ,
295- ...getQueryOptions ( )
289+ variables : reactiveVariables . value
296290 } )
297291
298292 startObserver ( )
@@ -325,8 +319,8 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
325319 ? useThrottleFn ( updateVariables , options . throttle )
326320 : updateVariables
327321
328- watch ( reactiveVariables , ( newVariables ) => {
329- optimizedUpdateVariables ( newVariables )
322+ watch ( reactiveVariables , ( updatedVariables ) => {
323+ optimizedUpdateVariables ( updatedVariables )
330324 } , {
331325 deep : true ,
332326 flush : 'post'
0 commit comments