Does vue-apollo
automatically unsubscribe the query when the View changes?
For example, I have two views routed to /users
and /orders
. /users
has a subscription to the users
table and /orders
has a subscription to the orders
table.
If I were on the /user
page, would the order
subscription still be in effect? If yes, how would I be able to turn it off?
Different versions of Vue Apollo are compatible with different versions of Vue: Vue Apollo v3 - Vue v2. Vue Apollo v4 - Vue v2 and Vue v3.
Vue is a modern JavaScript framework for building single-page applications. Apollo Client is a fully-fledged GraphQL client and state management library. Using Vue Apollo, we can combine them to substantially improve the developer experience involved in building complex UIs.
Since Apollo queries are bound to your component they will follow the lifecycle of your components, i.e. if your route changes (different components are renderd), your old components will be deleted and therefore your old queries will also be removed.
This is taken care of within Vue apollo by this mixin.
Take a look at the following part:
export function installMixin (Vue, vueVersion) {
Vue.mixin({
// Other irrelevant code for this question
destroyed: destroy,
})
}
This means it binds to the 'destroyed' event of each Vue component which will then trigger the destroy function (as defined by the Vue API reference):
function destroy () {
if (this.$_apollo) {
this.$_apollo.destroy()
}
}
So this process ensures your queries are destroyed and not in effect anymore when your component is destroyed.
I hope this answers your question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With