diff --git a/dist/vue-apollo.esm.js b/dist/vue-apollo.esm.js index 59a76376..57a8ee0e 100644 --- a/dist/vue-apollo.esm.js +++ b/dist/vue-apollo.esm.js @@ -364,6 +364,7 @@ function debounce (delay, atBegin, callback) { } var index_esm = /*#__PURE__*/Object.freeze({ + __proto__: null, throttle: throttle, debounce: debounce }); @@ -520,8 +521,10 @@ function () { _this.refresh(); }; - _cb = _this.options.throttle ? utils_2(_cb, _this.options.throttle) : _cb; - _cb = _this.options.debounce ? utils_3(_cb, _this.options.debounce) : _cb; + if (!_this.vm.$isServer) { + _cb = _this.options.throttle ? utils_2(_cb, _this.options.throttle) : _cb; + _cb = _this.options.debounce ? utils_3(_cb, _this.options.debounce) : _cb; + } _this._watchers.push(_this.vm.$watch(queryCb, _cb, { deep: _this.options.deep @@ -536,8 +539,11 @@ function () { if (typeof this.options.variables === 'function') { var cb = this.executeApollo.bind(this); - cb = this.options.throttle ? utils_2(cb, this.options.throttle) : cb; - cb = this.options.debounce ? utils_3(cb, this.options.debounce) : cb; + + if (!this.vm.$isServer) { + cb = this.options.throttle ? utils_2(cb, this.options.throttle) : cb; + cb = this.options.debounce ? utils_3(cb, this.options.debounce) : cb; + } this._watchers.push(this.vm.$watch(function () { return _this.options.variables.call(_this.vm); @@ -749,15 +755,7 @@ function (_SmartApollo) { _classCallCheck(this, SmartQuery); - // Simple query - if (!options.query) { - var query = options; - options = { - query: query - }; - } // Add reactive data related to the query - - + // Add reactive data related to the query if (vm.$data.$apolloData && !vm.$data.$apolloData.queries[key]) { vm.$set(vm.$data.$apolloData.queries, key, { loading: false @@ -772,6 +770,8 @@ function (_SmartApollo) { _defineProperty(_assertThisInitialized(_this), "_loading", false); + _defineProperty(_assertThisInitialized(_this), "_linkedSubscriptions", []); + if (vm.$isServer) { _this.firstRun = new Promise(function (resolve, reject) { _this._firstRunResolve = resolve; @@ -834,7 +834,31 @@ function (_SmartApollo) { return; } - this.sub.unsubscribe(); + this.sub.unsubscribe(); // Subscribe to more subs + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this._linkedSubscriptions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var sub = _step.value; + sub.stop(); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } } this.previousVariablesJson = variablesJson; // Create observer @@ -850,7 +874,33 @@ function (_SmartApollo) { } } - _get(_getPrototypeOf(SmartQuery.prototype), "executeApollo", this).call(this, variables); + _get(_getPrototypeOf(SmartQuery.prototype), "executeApollo", this).call(this, variables); // Subscribe to more subs + + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this._linkedSubscriptions[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var _sub = _step2.value; + + _sub.start(); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } } }, { key: "startQuerySubscription", @@ -1313,17 +1363,25 @@ function () { value: function addSmartQuery(key, options) { var _this3 = this; - var finalOptions = utils_5(options, this.vm); + var finalOptions = utils_5(options, this.vm); // Simple query + + if (!finalOptions.query) { + var query = finalOptions; + finalOptions = { + query: query + }; + } + var apollo = this.vm.$options.apollo; var defaultOptions = this.provider.defaultOptions; var $query; - if (apollo && apollo.$query) { - $query = apollo.$query; + if (defaultOptions && defaultOptions.$query) { + $query = defaultOptions.$query; } - if ((!apollo || !apollo.$query) && defaultOptions && defaultOptions.$query) { - $query = defaultOptions.$query; + if (apollo && apollo.$query) { + $query = _objectSpread2({}, $query || {}, {}, apollo.$query); } if ($query) { @@ -1368,6 +1426,11 @@ function () { options = utils_5(options, this.vm); var smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false); smart.autostart(); + + if (options.linkedQuery) { + options.linkedQuery._linkedSubscriptions.push(smart); + } + return smart; } } @@ -1476,7 +1539,11 @@ function () { } this.clients = options.clients || {}; - this.clients.defaultClient = this.defaultClient = options.defaultClient; + + if (options.defaultClient) { + this.clients.defaultClient = this.defaultClient = options.defaultClient; + } + this.defaultOptions = options.defaultOptions; this.watchLoading = options.watchLoading; this.errorHandler = options.errorHandler; @@ -2073,7 +2140,7 @@ function install(Vue, options) { } ApolloProvider.install = install; // eslint-disable-next-line no-undef -ApolloProvider.version = "3.0.0-rc.6"; // Apollo provider +ApolloProvider.version = "3.0.0-rc.7"; // Apollo provider var ApolloProvider$1 = ApolloProvider; // Components diff --git a/dist/vue-apollo.min.js b/dist/vue-apollo.min.js index b27e67cb..e66d10d3 100644 --- a/dist/vue-apollo.min.js +++ b/dist/vue-apollo.min.js @@ -1 +1 @@ -var VueApollo=function(t,o){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var i=0;i.provide() is deprecated. Use the 'apolloProvider' option instead with the provider object directly."),a({},e,this)}}]),e}();var E={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type:[Function,Object],required:!0},variables:{type:Object,default:void 0},fetchPolicy:{type:String,default:void 0},pollInterval:{type:Number,default:void 0},notifyOnNetworkStatusChange:{type:Boolean,default:void 0},context:{type:Object,default:void 0},update:{type:Function,default:function(t){return t}},skip:{type:Boolean,default:!1},debounce:{type:Number,default:0},throttle:{type:Number,default:0},clientId:{type:String,default:void 0},deep:{type:Boolean,default:void 0},tag:{type:String,default:"div"},prefetch:{type:Boolean,default:!0},options:{type:Object,default:function(){return{}}}},data:function(){return{result:{data:null,loading:!1,networkStatus:7,error:null},times:0}},watch:{fetchPolicy:function(t){this.$apollo.queries.query.setOptions({fetchPolicy:t})},pollInterval:function(t){this.$apollo.queries.query.setOptions({pollInterval:t})},notifyOnNetworkStatusChange:function(t){this.$apollo.queries.query.setOptions({notifyOnNetworkStatusChange:t})},"$data.$apolloData.loading":function(t){this.$emit("loading",!!t)}},apollo:{$client:function(){return this.clientId},query:function(){return c({query:function(){return"function"==typeof this.query?this.query(o):this.query},variables:function(){return this.variables},fetchPolicy:this.fetchPolicy,pollInterval:this.pollInterval,debounce:this.debounce,throttle:this.throttle,notifyOnNetworkStatusChange:this.notifyOnNetworkStatusChange,context:function(){return this.context},skip:function(){return this.skip},deep:this.deep,prefetch:this.prefetch},this.options,{manual:!0,result:function(t){var e=t,i=e.errors,o=e.loading,r=e.networkStatus,n=t.error;t=Object.assign({},t),i&&i.length&&((n=new Error("Apollo errors occurred (".concat(i.length,")"))).graphQLErrors=i);var s={};o?Object.assign(s,this.$_previousData,t.data):n?Object.assign(s,this.$apollo.queries.query.observer.getLastResult()||{},t.data):(s=t.data,this.$_previousData=t.data);var a=function(t){return 0 `subscribe` option is deprecated. Use the `$subscribe` option instead."),i.$subscribe)for(var s in i.$subscribe)this.$apollo.addSmartSubscription(s,i.$subscribe[s])}}}function K(t,e,i,o){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,o):t[e]=i)}function N(){this.$_apollo&&(this.$_apollo.destroy(),this.$_apollo=null)}function V(t,e){t.mixin(c({},"1"===e?{init:M}:{},{},"2"===e?{data:function(){return{$apolloData:{queries:{},loading:0,data:this.$_apolloInitData}}},beforeCreate:function(){M.call(this),function(){var i=this;this.$_apolloInitData={};var t=this.$options.apollo;if(t){var e=function(e){"$"!==e.charAt(0)&&(t[e].manual||I(i.$options.props,e)||I(i.$options.computed,e)||I(i.$options.methods,e)||Object.defineProperty(i,e,{get:function(){return i.$data.$apolloData.data[e]},set:function(t){return i.$_apolloInitData[e]=t},enumerable:!0,configurable:!0}))};for(var o in t)e(o)}}.call(this)},serverPrefetch:function(){if(this.$_apolloPromises)return Promise.all(this.$_apolloPromises)}}:{},{created:T,destroyed:N}))}var F=["$subscribe"];function H(t,e){if(!H.installed){H.installed=!0;var i=(k.Vue=t).version.substr(0,t.version.indexOf(".")),l=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,i){if(!t)return e;if(!e)return t;for(var o=Object.assign({},_(t,F),t.data),r=Object.assign({},_(e,F),e.data),n={},s=0;s.provide() is deprecated. Use the 'apolloProvider' option instead with the provider object directly."),a({},e,this)}}]),e}();var E={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type:[Function,Object],required:!0},variables:{type:Object,default:void 0},fetchPolicy:{type:String,default:void 0},pollInterval:{type:Number,default:void 0},notifyOnNetworkStatusChange:{type:Boolean,default:void 0},context:{type:Object,default:void 0},update:{type:Function,default:function(t){return t}},skip:{type:Boolean,default:!1},debounce:{type:Number,default:0},throttle:{type:Number,default:0},clientId:{type:String,default:void 0},deep:{type:Boolean,default:void 0},tag:{type:String,default:"div"},prefetch:{type:Boolean,default:!0},options:{type:Object,default:function(){return{}}}},data:function(){return{result:{data:null,loading:!1,networkStatus:7,error:null},times:0}},watch:{fetchPolicy:function(t){this.$apollo.queries.query.setOptions({fetchPolicy:t})},pollInterval:function(t){this.$apollo.queries.query.setOptions({pollInterval:t})},notifyOnNetworkStatusChange:function(t){this.$apollo.queries.query.setOptions({notifyOnNetworkStatusChange:t})},"$data.$apolloData.loading":function(t){this.$emit("loading",!!t)}},apollo:{$client:function(){return this.clientId},query:function(){return c({query:function(){return"function"==typeof this.query?this.query(r):this.query},variables:function(){return this.variables},fetchPolicy:this.fetchPolicy,pollInterval:this.pollInterval,debounce:this.debounce,throttle:this.throttle,notifyOnNetworkStatusChange:this.notifyOnNetworkStatusChange,context:function(){return this.context},skip:function(){return this.skip},deep:this.deep,prefetch:this.prefetch},this.options,{manual:!0,result:function(t){var e=t,i=e.errors,r=e.loading,o=e.networkStatus,n=t.error;t=Object.assign({},t),i&&i.length&&((n=new Error("Apollo errors occurred (".concat(i.length,")"))).graphQLErrors=i);var s={};r?Object.assign(s,this.$_previousData,t.data):n?Object.assign(s,this.$apollo.queries.query.observer.getLastResult()||{},t.data):(s=t.data,this.$_previousData=t.data);var a=function(t){return 0 `subscribe` option is deprecated. Use the `$subscribe` option instead."),i.$subscribe)for(var s in i.$subscribe)this.$apollo.addSmartSubscription(s,i.$subscribe[s])}}}function K(t,e,i,r){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,r):t[e]=i)}function N(){this.$_apollo&&(this.$_apollo.destroy(),this.$_apollo=null)}function V(t,e){t.mixin(c({},"1"===e?{init:M}:{},{},"2"===e?{data:function(){return{$apolloData:{queries:{},loading:0,data:this.$_apolloInitData}}},beforeCreate:function(){M.call(this),function(){var i=this;this.$_apolloInitData={};var t=this.$options.apollo;if(t){var e=function(e){"$"!==e.charAt(0)&&(t[e].manual||I(i.$options.props,e)||I(i.$options.computed,e)||I(i.$options.methods,e)||Object.defineProperty(i,e,{get:function(){return i.$data.$apolloData.data[e]},set:function(t){return i.$_apolloInitData[e]=t},enumerable:!0,configurable:!0}))};for(var r in t)e(r)}}.call(this)},serverPrefetch:function(){if(this.$_apolloPromises)return Promise.all(this.$_apolloPromises)}}:{},{created:T,destroyed:N}))}var F=["$subscribe"];function H(t,e){if(!H.installed){H.installed=!0;var i=(k.Vue=t).version.substr(0,t.version.indexOf(".")),l=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,i){if(!t)return e;if(!e)return t;for(var r=Object.assign({},_(t,F),t.data),o=Object.assign({},_(e,F),e.data),n={},s=0;s