INNER CODE UNIT · TypeScript

useAsyncGql

Diizzayy/nuxt-graphql-client · src/runtime/composables/index.ts:339

export function useAsyncGql(...args: any[]) {
  const toReactive = (v: any) => v && isRef(v) ? v : reactive(v)
  const arg0 = args?.[0]
  const options = (typeof arg0 === 'object' && 'options' in arg0 ? args[0].options : args[2]) ?? {}
  const operation = (typeof arg0 === 'object' && 'operation' in arg0 ? args[0].operation : args[0]) ?? undefined
  const variables = (typeof arg0 === 'object' && 'variables' in arg0 ? toReactive(args[0].variables) : args[1] && toReactive(args[1])) ?? undefined
  if (variables) {
    options.watch = options.watch || []
    options.watch.push(variables)
  }
  const key = `gql:data:${hash({ operation, variables })}`
  return useAsyncData(key, () => useGql()(operation, unref(variables)), options)
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…