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

useAsyncGql: all variable changes trigger execution #497

Open
4ndre4s opened this issue Jun 26, 2024 · 0 comments
Open

useAsyncGql: all variable changes trigger execution #497

4ndre4s opened this issue Jun 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@4ndre4s
Copy link

4ndre4s commented Jun 26, 2024

Environment

Any

Describe the bug

All variables passed to useAsyncGql are watched by default. There is no way to override the watch property of the underlying useAsyncData, at least all variables will be watched.

src/runtime/composables/index.ts#L332

export function useAsyncGql (...args: any[]) {
  const toReactive = (v: any) => v && isRef(v) ? v : reactive(v)
  const options = (typeof args?.[0] !== 'string' && 'options' in args?.[0] ? args[0].options : args[2]) ?? {}
  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] ? toReactive(args[0].variables) : args[1] && toReactive(args[1])) ?? undefined
  if (variables) {
    options.watch = options.watch || []
    // ⬇️ this line here causes the issue
    options.watch.push(variables)
  }
  const key = `gql:data:${hash({ operation, variables })}`
  return useAsyncData(key, () => useGql()(operation, unref(variables)), options)
}

As you can see here, useAsyncData requires every watch source to be explicitely registered.

I understand that one wants to keep backwards compatibility and not break existing implementations, but would it be possible to - for example - provide a flag autowatch=false (or just to use the value of options.watch) to disable the by default registration?

Expected behaviour

The variables should not be watched by default. At least, there should be a flag to turn off the automatic registration.

Reproduction

No response

Additional context

No response

Logs

No response

@4ndre4s 4ndre4s added the bug Something isn't working label Jun 26, 2024
@4ndre4s 4ndre4s changed the title useAsyncGql: Variables are automatically watched useAsyncGql: all variable changes trigger execution Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant