From b67ff78d6a595d9ec67382e74aaffef12439db4a Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Mon, 20 Sep 2021 18:19:43 +0200 Subject: [PATCH] fix(smart apollo): ensure SmartQuery variables still function when watched expression evaluated (#1161), closes #991 --- packages/vue-apollo-option/src/smart-apollo.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/vue-apollo-option/src/smart-apollo.js b/packages/vue-apollo-option/src/smart-apollo.js index 80114c8..e62ebe0 100644 --- a/packages/vue-apollo-option/src/smart-apollo.js +++ b/packages/vue-apollo-option/src/smart-apollo.js @@ -112,10 +112,18 @@ export default class SmartApollo { cb = this.options.throttle ? throttle(cb, this.options.throttle) : cb cb = this.options.debounce ? debounce(cb, this.options.debounce) : cb } - this._watchers.push(this.vm.$watch(() => this.options.variables.call(this.vm), cb, { - immediate: true, - deep: this.options.deep, - })) + this._watchers.push( + this.vm.$watch( + () => typeof this.options.variables === 'function' + ? this.options.variables.call(this.vm) + : this.options.variables, + cb, + { + immediate: true, + deep: this.options.deep, + }, + ), + ) } else { this.executeApollo(this.options.variables) }