Open farin opened 2 years ago
To make this work, you can wrap your variables in a computed.
<script lang="ts" setup>
import { useProductListQuery } from '~~/generated/graphql'
const category = ref('fashion')
const variables = computed(() => ({ category: category.value, limit: 10 }))
const { data } = useProductListQuery({ variables })
</script>
And if you're looking for Ref
or ComputedRef
via a lower level Maybe
'd field, like I am:
schema: ../../../internal/graphql/schema/*.gql
documents: ./src/lib/api/*.gql
generates:
./src/lib/api/index.ts:
plugins:
- typescript
- typescript-operations
- typescript-vue-urql
config:
inputMaybeValue: T | Ref<T> | ComputedRef<T> # this specifically
I created a PR to fix this https://github.com/dotansimha/graphql-code-generator-community/pull/659 but so far have not heard anything
Related to @graphql-codegen/typescript-vue-urql
Current implementation
useQuery
from urlq supports Ref variables (with internal MaybeRef type asMaybeRef<T> = T | Ref<T>
)see following example
and such query is reactive. Reloading data every time category ref is changes
But generated helpers
useProductListQuery
in this case accepts only T, not RefProposed usage
There is no reason for it as helpers is only wrapper around useQuery. (Someone can call this issue a bug instead of feature request)