diff --git a/src/runtime/composables/index.ts b/src/runtime/composables/index.ts index 95a12d5..c2ff7e3 100644 --- a/src/runtime/composables/index.ts +++ b/src/runtime/composables/index.ts @@ -272,7 +272,8 @@ const useGqlErrorState = () => useState('_gqlErrors', () => nul */ export function useAsyncGql< T extends GqlOps, -P extends Parameters['0'], +p extends Parameters['0'], +P extends { [K in keyof p]: Ref | p[K] }, R extends AsyncData>, GqlError>, O extends Parameters['2']> (options: { operation: T, variables?: P, options?: O }): Promise @@ -285,14 +286,19 @@ O extends Parameters['2']> (options: { operation: T, variab */ export function useAsyncGql< T extends GqlOps, -P extends Parameters['0'], +p extends Parameters['0'], +P extends { [K in keyof p]: Ref | p[K] }, R extends AsyncData>, GqlError>, O extends Parameters['2']> (operation: T, variables?: P, options?: O): Promise export function useAsyncGql (...args: any[]) { const operation = (typeof args?.[0] !== 'string' && 'operation' in args?.[0] ? args[0].operation : args[0]) ?? undefined - const variables = (typeof args?.[0] !== 'string' && 'variables' in args?.[0] ? args[0].variables : args[1]) ?? undefined - const options = (typeof args?.[0] !== 'string' && 'options' in args?.[0] ? args[0].options : args[2]) ?? undefined + const variables = (typeof args?.[0] !== 'string' && 'variables' in args?.[0] ? reactive(args[0].variables) : reactive(args[1])) ?? undefined + const options = (typeof args?.[0] !== 'string' && 'options' in args?.[0] ? args[0].options : args[2]) ?? {} + if (variables) { + options.watch = options.watch || [] + options.watch.push(variables) + } const key = hash({ operation, variables }) // @ts-ignore return useAsyncData(key, () => useGql()(operation, variables), options)