How to pass dynamic or different query strings to useQuery API #1399
vikashpisces
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Vue 3, I wanted to build a query builder which will have a text box for query and an output field to display result.
I was trying to use useQuery with a reactive query field, binding done to the text box but for some reason useQuery always uses the first query string passed to it, does not take a new string changes. Any workaround please? My code is here:
// TestComponent.vue
TestComponent.vue.txt
//useGraphQL.ts
import { useQuery } from '@vue/apollo-composable'
import { gql } from 'graphql-tag'
export const useGraphQL = ($query: string, $variables: Object = {}, $options: Object = {}) => {
const {
result,
loading,
error,
refetch,
variables,
onResult,
onError
} = useQuery(gql
${$query}
, $variables, $options)return {
result,
loading,
error,
refetch,
variables,
onResult,
onError
}
}
since query reactive variable is default empty, useQuery sticks with the empty query and does not change even if we paste a valid query from UI.
Beta Was this translation helpful? Give feedback.
All reactions