Replies: 22 comments
-
Hi, i searched for it a lot too, but it is writtin in their documentation vue apollo v4e
just add the "refetch" to the useQuery line and call it from the button click event. Best Regards |
Beta Was this translation helpful? Give feedback.
-
@lTimeless, thanks for the answer. Does the example query the server two times (one in setup and one in refetch) or only one time (in refetch)? Thanks. |
Beta Was this translation helpful? Give feedback.
-
@ozum You could Disable the query and on button click enable it andthan refetch the query. |
Beta Was this translation helpful? Give feedback.
-
@lTimeless thanks for the answer. |
Beta Was this translation helpful? Give feedback.
-
Hello @ozum I'm experiencing the same issue. |
Beta Was this translation helpful? Give feedback.
-
@aaronschweig currently I have to switch back to old API, because some of the libraries I use did not support composition API yet. Using old API, I could not find a solution other than |
Beta Was this translation helpful? Give feedback.
-
Hello guys, any solution for it yet? same problem. |
Beta Was this translation helpful? Give feedback.
-
Hello @mtsmachado8 i've found a working solution. const queryOptions = ref({
// whatever options you need
enabled: false
})
const {result} = useQuery(<query>, <variables>,queryOptions)
// Do with the result what you need
const onClick = () => {
queryOptions.value.enabled = true
} This works for me and queries only once, when the Button is clicked. For me, instead of only doing the const {result, refetch} = useQuery(<query>, <variables>,queryOptions)
const onClick = () => {
if (!queryOptions.value.enabled) {
queryOptions.value.enabled = true
return
}
refetch()
} I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Thankss @aaronschweig, it really helped!!! |
Beta Was this translation helpful? Give feedback.
-
This seems very inelegant. Executing a query on click (or whatever event) should work as expected imo. |
Beta Was this translation helpful? Give feedback.
-
Is there a solution for this if you arent even using an event to trigger query? I'm using quasar ssr and am getting There is nothing special triggering the query its just within the setup function. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to prevent the initial query from executing with useQuery? My code is written as follows: export default function useUserQuery() {
const { refetch } = useQuery(UserQuery);
return async function fetchUser(userId) {
const { data } = await refetch({ userId });
return data.user;
};
} This works as intended, but the initial query is being run (without variables and thus is throwing an error in the console, but all subsequent queries with |
Beta Was this translation helpful? Give feedback.
-
Can you get this disable/enable demo to work with the latest alpha version? |
Beta Was this translation helpful? Give feedback.
-
Both |
Beta Was this translation helpful? Give feedback.
-
Also, seems like there's no clean way to perform a one-shot request or reuse the same one on-demand (without loading it first). In Options API you could do this const result = await this.$apollo.query({
query: gql`...`,
variables: { param: 'hello' },
}) You still can, via const result = await root.$apollo.query({
query: gql`...`,
variables: { param: 'hello' },
}) Using I guess I could create a Promise which wraps the result ref and resolve when it emits, but it feels a bit hacky. |
Beta Was this translation helpful? Give feedback.
-
Besides |
Beta Was this translation helpful? Give feedback.
-
@paulhaem Getting that error as well. And example-code that triggers the error above. It is in a vuex-module. |
Beta Was this translation helpful? Give feedback.
-
I tried to do this instead now @Akryum: And I am getting this error in console (catching it in a try/catch): Update: I saw that I missed to pass variable, but I changed that and I'm getting the error anyway. |
Beta Was this translation helpful? Give feedback.
-
In firefox console getting this error: |
Beta Was this translation helpful? Give feedback.
-
Might be on track to something. This issue pointed me in right direction: #1029 (comment) I do not use Vite-plugin, so I removed it manually... |
Beta Was this translation helpful? Give feedback.
-
The right way to do it is not to use import { useApolloClient } from '@vue/apollo-composable'
const { client } = useApolloClient()
const onClick = async () => {
const { data } = await client.query({
query: someQuery,
variables: someVariablesIfNeeded,
})
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for the library and effort given.
Similar to #121, I need an example how to query after an event (such as button click) in v4 composition API?
Further info:
I'm using
vue-apollo
withNuxt
. (Not@nuxtjs/apollo
, because it doesn't supportvue-apollo
v4 yet.)I tried below methods:
Many thanks,
Beta Was this translation helpful? Give feedback.
All reactions