logaretm / villus

🏎 A tiny and fast GraphQL client for Vue.js
https://villus.dev
MIT License
790 stars 31 forks source link

Fix bug where calling `query.unwatchVariables()` can error #164

Closed callumacrae closed 2 years ago

callumacrae commented 2 years ago

If there are no variables passed to the query, or if the variables aren't watchable, isWatchingVariables.value will be true, but stopVarsWatcher won't be defined, causing query.unwatchVariables() to throw an error when called.

Setting the default value of the isWatchingVariables ref to false by default fixes this, as it's set to true when beginWatchVars is called if the vars are watched.

For reference, the reason I'm calling unwatchVariables on a query where the variables aren't being watched anyway is I'm wrapping my villus queries in a hook which stops the variables from being watched when the component isn't on screen (I'm using ionic, it's complicated).

logaretm commented 2 years ago

That makes sense, thanks!