diff --git a/dist/vue-apollo.esm.js b/dist/vue-apollo.esm.js index 85ddec7..aed3b68 100644 --- a/dist/vue-apollo.esm.js +++ b/dist/vue-apollo.esm.js @@ -2348,7 +2348,34 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol +var asyncToGenerator = function (fn) { + return function () { + var gen = fn.apply(this, arguments); + return new Promise(function (resolve, reject) { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + return Promise.resolve(value).then(function (value) { + step("next", value); + }, function (err) { + step("throw", err); + }); + } + } + + return step("next"); + }); + }; +}; var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { @@ -2832,12 +2859,14 @@ var SmartQuery = function (_SmartApollo) { if (typeof data === 'undefined') { // No result - } else if (typeof this.options.update === 'function') { - this.vm[this.key] = this.options.update.call(this.vm, data); - } else if (data[this.key] === undefined && !this.options.manual) { - console.error('Missing ' + this.key + ' attribute on result', data); } else if (!this.options.manual) { - this.vm[this.key] = data[this.key]; + if (typeof this.options.update === 'function') { + this.vm.$set(this.vm.$apolloData.data, this.key, this.options.update.call(this.vm, data)); + } else if (data[this.key] === undefined) { + console.error('Missing ' + this.key + ' attribute on result', data); + } else { + this.vm.$set(this.vm.$apolloData.data, this.key, data[this.key]); + } } else if (!hasResultCallback) { console.error(this.key + ' query must have a \'result\' hook in manual mode'); } @@ -3752,9 +3781,113 @@ var CApolloSubscribeToMore = { } }; +var CApolloMutation = { + props: { + mutation: { + type: Object, + required: true + }, + + variables: { + type: Object, + default: undefined + }, + + optimisticResponse: { + type: Object, + default: undefined + }, + + update: { + type: Function, + default: undefined + }, + + refetchQueries: { + type: Function, + default: undefined + }, + + tag: { + type: String, + default: 'div' + } + }, + + data: function data() { + return { + loading: false, + error: null + }; + }, + + + methods: { + mutate: function mutate(options) { + var _this = this; + + return asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _this.loading = true; + _this.error = null; + _context.prev = 2; + _context.next = 5; + return _this.$apollo.mutate(_extends({ + mutation: _this.mutation, + variables: _this.variables, + optimisticResponse: _this.optimisticResponse, + update: _this.update, + refetchQueries: _this.refetchQueries + }, options)); + + case 5: + _this.$emit('done'); + _context.next = 12; + break; + + case 8: + _context.prev = 8; + _context.t0 = _context['catch'](2); + + _this.error = _context.t0; + _this.$emit('error', _context.t0); + + case 12: + _this.loading = false; + + case 13: + case 'end': + return _context.stop(); + } + } + }, _callee, _this, [[2, 8]]); + }))(); + } + }, + + render: function render(h) { + var result = this.$scopedSlots.default({ + mutate: this.mutate, + loading: this.loading, + error: this.error + }); + if (Array.isArray(result)) { + result = result.concat(this.$slots.default); + } else { + result = [result].concat(this.$slots.default); + } + return h(this.tag, result); + } +}; + var keywords = ['$subscribe']; var launch = function launch() { + var _this = this; + var apolloProvider = this.$apolloProvider; if (this._apolloLaunched || !apolloProvider) return; @@ -3782,10 +3915,22 @@ var launch = function launch() { defineReactiveSetter(this.$apollo, 'watchLoading', apollo.$watchLoading); // watchQuery - for (var key in apollo) { + + var _loop = function _loop(key) { if (key.charAt(0) !== '$') { - this.$apollo.addSmartQuery(key, apollo[key]); + Object.defineProperty(_this, key, { + get: function get$$1() { + return _this.$apolloData.data[key]; + }, + enumerable: true, + configurable: true + }); + _this.$apollo.addSmartQuery(key, apollo[key]); } + }; + + for (var key in apollo) { + _loop(key); } if (apollo.subscribe) { @@ -3793,8 +3938,8 @@ var launch = function launch() { } if (apollo.$subscribe) { - for (var _key in apollo.$subscribe) { - this.$apollo.addSmartSubscription(_key, apollo.$subscribe[_key]); + for (var key in apollo.$subscribe) { + this.$apollo.addSmartSubscription(key, apollo.$subscribe[key]); } } } @@ -3865,7 +4010,8 @@ function install(Vue, options) { return this.$options.apollo ? { '$apolloData': { queries: {}, - loading: 0 + loading: 0, + data: {} } } : {}; } @@ -3887,19 +4033,22 @@ function install(Vue, options) { Vue.component('ApolloQuery', CApolloQuery); Vue.component('apollo-subscribe-to-more', CApolloSubscribeToMore); Vue.component('ApolloSubscribeToMore', CApolloSubscribeToMore); + Vue.component('apollo-mutation', CApolloMutation); + Vue.component('ApolloMutation', CApolloMutation); } } ApolloProvider.install = install; // eslint-disable-next-line no-undef -ApolloProvider.version = "3.0.0-beta.5"; +ApolloProvider.version = "3.0.0-beta.6"; // Apollo provider var ApolloProvider$1 = ApolloProvider; // Components var ApolloQuery = CApolloQuery; var ApolloSubscribeToMore = CApolloSubscribeToMore; +var ApolloMutation = CApolloMutation; // Auto-install var GlobalVue = null; @@ -3913,4 +4062,4 @@ if (GlobalVue) { } export default ApolloProvider; -export { install, ApolloProvider$1 as ApolloProvider, ApolloQuery, ApolloSubscribeToMore, willPrefetch }; +export { install, ApolloProvider$1 as ApolloProvider, ApolloQuery, ApolloSubscribeToMore, ApolloMutation, willPrefetch }; diff --git a/dist/vue-apollo.min.js b/dist/vue-apollo.min.js index cb1e3fc..ee5eb36 100644 --- a/dist/vue-apollo.min.js +++ b/dist/vue-apollo.min.js @@ -1 +1 @@ -var VueApollo=function(t){"use strict";var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=200,o="__lodash_hash_undefined__",i=1/0,n=9007199254740991,s="[object Arguments]",a="[object Function]",u="[object GeneratorFunction]",l="[object Symbol]",c=/^\[object .+?Constructor\]$/,h=/^(?:0|[1-9]\d*)$/,f="object"==typeof e&&e&&e.Object===Object&&e,p="object"==typeof self&&self&&self.Object===Object&&self,v=f||p||Function("return this")();function y(t,e){return!!(t?t.length:0)&&function(t,e,r){if(e!=e)return function(t,e,r,o){var i=t.length,n=r+(o?1:-1);for(;o?n--:++n-1}function d(t,e,r){for(var o=-1,i=t?t.length:0;++o-1},K.prototype.set=function(t,e){var r=this.__data__,o=H(r,t);return o<0?r.push([t,e]):r[o][1]=e,this},I.prototype.clear=function(){this.__data__={hash:new V,map:new(N||K),string:new V}},I.prototype.delete=function(t){return U(this,t).delete(t)},I.prototype.get=function(t){return U(this,t).get(t)},I.prototype.has=function(t){return U(this,t).has(t)},I.prototype.set=function(t,e){return U(this,t).set(t,e),this},F.prototype.add=F.prototype.push=function(t){return this.__data__.set(t,o),this},F.prototype.has=function(t){return this.__data__.has(t)};var X=D?k(D,Object):ht,Y=D?function(t){for(var e=[];t;)g(e,X(t)),t=E(t);return e}:ht;function Z(t){return nt(t)||rt(t)||!!(C&&t&&t[C])}function tt(t,e){return!!(e=null==e?n:e)&&("number"==typeof t||h.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=n}(t.length)&&!at(t)}function at(t){var e=ut(t)?q.call(t):"";return e==a||e==u}function ut(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function lt(t){return!!t&&"object"==typeof t}function ct(t){return st(t)?W(t,!0):J(t)}function ht(){return[]}var ft=(ot=function(t,e){return null==t?{}:(e=b(function t(e,r,o,i,n){var s=-1,a=e.length;for(o||(o=Z),n||(n=[]);++s0&&o(u)?r>1?t(u,r-1,o,i,n):g(n,u):i||(n[n.length]=u)}return n}(e,1),et),function(t,e){return function(t,e,r){for(var o=-1,i=e.length,n={};++o=r&&(a=_,u=!1,e=new F(e));t:for(;++s=e||r<0||h&&t-l>=n}function y(){var t=At();if(v(t))return d(t);a=setTimeout(y,function(t){var r=e-(t-u);return h?jt(r,n-(t-l)):r}(t))}function d(t){return a=void 0,f&&o?p(t):(o=i=void 0,s)}function b(){var t=At(),r=v(t);if(o=arguments,i=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(y,e),c?p(t):s}(u);if(h)return a=setTimeout(y,e),p(u)}return void 0===a&&(a=setTimeout(y,e)),s}return e=xt(e)||0,qt(r)&&(c=!!r.leading,n=(h="maxWait"in r)?St(xt(r.maxWait)||0,e):n,f="trailing"in r?!!r.trailing:f),b.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=i=a=void 0},b.flush=function(){return void 0===a?s:d(At())},b}function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function xt(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ot.call(t)==yt}(t))return vt;if(qt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=qt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(dt,"");var r=gt.test(t);return r||mt.test(t)?_t(t.slice(2),r?2:8):bt.test(t)?vt:+t}var Qt=function(t,e,r){var o=!0,i=!0;if("function"!=typeof t)throw new TypeError(pt);return qt(r)&&(o="leading"in r?!!r.leading:o,i="trailing"in r?!!r.trailing:i),Pt(t,e,{leading:o,maxWait:e,trailing:i})},Et="Expected a function",Lt=NaN,Tt="[object Symbol]",Ct=/^\s+|\s+$/g,Dt=/^[-+]0x[0-9a-f]+$/i,Mt=/^0b[01]+$/i,Nt=/^0o[0-7]+$/i,Rt=parseInt,Vt="object"==typeof e&&e&&e.Object===Object&&e,Kt="object"==typeof self&&self&&self.Object===Object&&self,It=Vt||Kt||Function("return this")(),Ft=Object.prototype.toString,Wt=Math.max,Ht=Math.min,Gt=function(){return It.Date.now()};function Jt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Bt(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ft.call(t)==Tt}(t))return Lt;if(Jt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Jt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(Ct,"");var r=Mt.test(t);return r||Nt.test(t)?Rt(t.slice(2),r?2:8):Dt.test(t)?Lt:+t}var Ut=function(t,e,r){var o,i,n,s,a,u,l=0,c=!1,h=!1,f=!0;if("function"!=typeof t)throw new TypeError(Et);function p(e){var r=o,n=i;return o=i=void 0,l=e,s=t.apply(n,r)}function v(t){var r=t-u;return void 0===u||r>=e||r<0||h&&t-l>=n}function y(){var t=Gt();if(v(t))return d(t);a=setTimeout(y,function(t){var r=e-(t-u);return h?Ht(r,n-(t-l)):r}(t))}function d(t){return a=void 0,f&&o?p(t):(o=i=void 0,s)}function b(){var t=Gt(),r=v(t);if(o=arguments,i=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(y,e),c?p(t):s}(u);if(h)return a=setTimeout(y,e),p(u)}return void 0===a&&(a=setTimeout(y,e)),s}return e=Bt(e)||0,Jt(r)&&(c=!!r.leading,n=(h="maxWait"in r)?Wt(Bt(r.maxWait)||0,e):n,f="trailing"in r?!!r.trailing:f),b.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=i=a=void 0},b.flush=function(){return void 0===a?s:d(Gt())},b},zt={};function Xt(t){return function(e,r){return"number"==typeof r?t(e,r):t(e,r.wait,r)}}var Yt=Xt(Qt),Zt=Xt(Ut);function te(t,e){for(;"function"==typeof t;)t=t.call(e);return t}var ee="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},re=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},oe=function(){function t(t,e){for(var r=0;r3&&void 0!==arguments[3])||arguments[3];if(re(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=r,this.options=Object.assign({},o),this._skip=!1,this._watchers=[],this._destroyed=!1,"function"==typeof this.options.query){var s=this.options.query.bind(this.vm);this.options.query=s(),this._watchers.push(this.vm.$watch(s,function(t){i.options.query=t,i.refresh()}))}if("function"==typeof this.options.document){var a=this.options.document.bind(this.vm);this.options.document=a(),this._watchers.push(this.vm.$watch(a,function(t){i.options.document=t,i.refresh()}))}if("function"==typeof this.options.context){var u=this.options.context.bind(this.vm);this.options.context=u(),this._watchers.push(this.vm.$watch(u,function(t){i.options.context=t,i.refresh()}))}this.vm.$isServer&&(this.options.fetchPolicy="cache-first"),n&&this.autostart()}return oe(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._watchers.push(this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0})):this.options.skip?this._skip=!0:this.start()}},{key:"skipChanged",value:function(t,e){t!==e&&(this.skip=t)}},{key:"refresh",value:function(){this._skip||(this.stop(),this.start())}},{key:"start",value:function(){var t=this;if(this.starting=!0,"function"==typeof this.options.variables){var e=this.executeApollo.bind(this);e=this.options.throttle?Yt(e,this.options.throttle):e,e=this.options.debounce?Zt(e,this.options.debounce):e,this.unwatchVariables=this.vm.$watch(function(){return t.options.variables.call(t.vm)},e,{immediate:!0})}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){this.unwatchVariables&&(this.unwatchVariables(),this.unwatchVariables=null),this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=ft(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(){throw new Error("Not implemented")}},{key:"errorHandler",value:function(){for(var t,e,r,o=arguments.length,i=Array(o),n=0;n3&&void 0!==arguments[3])||arguments[3];(re(this,e),o.query)||(o={query:o});t.$data.$apolloData&&!t.$data.$apolloData.queries[r]&&t.$set(t.$data.$apolloData.queries,r,{loading:!1});var n=ae(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r,o,i));return n.type="query",n.vueApolloSpecialKeys=ce,n._loading=!1,n}return se(e,le),oe(e,[{key:"stop",value:function(){ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t)),this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)}));var r=this.maySetLoading();r.loading||this.nextResult(r),ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"maySetLoading",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.observer.currentResult();return(t||e.loading)&&(this.loading||this.applyLoadingModifier(1),this.loading=!0),e}},{key:"nextResult",value:function(t){var e=t.data;t.loading||this.loadingDone();var r="function"==typeof this.options.result;void 0===e||("function"==typeof this.options.update?this.vm[this.key]=this.options.update.call(this.vm,e):void 0!==e[this.key]||this.options.manual?this.options.manual?r||console.error(this.key+" query must have a 'result' hook in manual mode"):this.vm[this.key]=e[this.key]:console.error("Missing "+this.key+" attribute on result",e)),r&&this.options.result.call(this.vm,t)}},{key:"catchError",value:function(t){ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone()}},{key:"watchLoading",value:function(){for(var t,e,r,o=arguments.length,i=Array(o),n=0;n0&&void 0!==arguments[0]?arguments[0]:null;if(!t||!t.client){if("object"===ee(this.client))return this.client;if(this.client){if(this.provider.clients){var e=this.provider.clients[this.client];if(!e)throw new Error("[vue-apollo] Missing client '"+this.client+"' in 'apolloProvider'");return e}throw new Error("[vue-apollo] Missing 'clients' options in 'apolloProvider'")}return this.provider.defaultClient}var r=this.provider.clients[t.client];if(!r)throw new Error("[vue-apollo] Missing client '"+t.client+"' in 'apolloProvider'");return r}},{key:"watchQuery",value:function(t){var e=this,r=this.getClient(t).watchQuery(t),o=r.subscribe.bind(r);return r.subscribe=function(t){var r=o(t);return e._apolloSubscriptions.push(r),r},r}},{key:"mutate",value:function(t){return this.getClient(t).mutate(t)}},{key:"subscribe",value:function(t){var e=this;if(!this.vm.$isServer){var r=this.getClient(t).subscribe(t),o=r.subscribe.bind(r);return r.subscribe=function(t){var r=o(t);return e._apolloSubscriptions.push(r),r},r}}},{key:"addSmartQuery",value:function(t,e){var r=this;e=te(e,this.vm);var o=this.queries[t]=new he(this.vm,t,e,!1);if(o.autostart(),!this.vm.$isServer){var i=e.subscribeToMore;i&&(Array.isArray(i)?i.forEach(function(e,i){r.addSmartSubscription(""+t+i,ie({},e,{linkedQuery:o}))}):this.addSmartSubscription(t,ie({},i,{linkedQuery:o})))}return o}},{key:"addSmartSubscription",value:function(t,e){if(!this.vm.$isServer){e=te(e,this.vm);var r=this.subscriptions[t]=new fe(this.vm,t,e,!1);return r.autostart(),r}}},{key:"defineReactiveSetter",value:function(t,e){var r=this;this._watchers.push(this.vm.$watch(e,function(e){r[t]=e},{immediate:!0}))}},{key:"destroy",value:function(){var t=!0,e=!1,r=void 0;try{for(var o,i=this._watchers[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,r=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw r}}for(var n in this.queries)this.queries[n].destroy();for(var s in this.subscriptions)this.subscriptions[s].destroy();this._apolloSubscriptions.forEach(function(t){t.unsubscribe()}),this._apolloSubscriptions=null,this.vm=null}},{key:"provider",get:function(){return this.vm.$apolloProvider}},{key:"loading",get:function(){return this.vm.$data.$apolloData&&0!==this.vm.$data.$apolloData.loading}},{key:"skipAllQueries",set:function(t){for(var e in this.queries)this.queries[e].skip=t}},{key:"skipAllSubscriptions",set:function(t){for(var e in this.subscriptions)this.subscriptions[e].skip=t}},{key:"skipAll",set:function(t){this.skipAllQueries=t,this.skipAllSubscriptions=t}}]),t}(),ve=function(){function t(e){if(re(this,t),!e)throw new Error("Options argument required");this.clients=e.clients||{},this.clients.defaultClient=this.defaultClient=e.defaultClient,this.defaultOptions=e.defaultOptions,this.watchLoading=e.watchLoading,this.errorHandler=e.errorHandler,this.prefetchQueries=[]}return oe(t,[{key:"provide",value:function(){return function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:"$apolloProvider",this)}},{key:"addQueryToPrefetch",value:function(t,e){this.prefetchQueries.push({queryOptions:t,client:e})}},{key:"prefetchComponent",value:function(t,e){var r;r=t;var o=(t=zt.Vue.util.mergeOptions({},r)).apollo;if(o){var i=o.$client;for(var n in o){var s=o[n];"$"===n.charAt(0)||s.query&&(void 0!==s.ssr&&!s.ssr||void 0===s.prefetch||!s.prefetch)||this.addQueryToPrefetch(s,s.client||i)}}}},{key:"prefetchComponents",value:function(t){var e=!0,r=!1,o=void 0;try{for(var i,n=t[Symbol.iterator]();!(e=(i=n.next()).done);e=!0){var s=i.value;this.prefetchComponent(s)}}catch(t){r=!0,o=t}finally{try{!e&&n.return&&n.return()}finally{if(r)throw o}}}},{key:"prefetchAll",value:function(t,e,r){var o=this;r||!e||Array.isArray(e)||(r=e,e=void 0);var i=Object.assign({},{includeGlobal:!0},r);return e&&this.prefetchComponents(e),i.includeGlobal&&this.prefetchComponents(ye.filter(function(e){e.component;var r=e.contextCallback,o=!0;return"function"==typeof r&&(o=!!r(t)),o}).map(function(t){return t.component}),t),Promise.all(this.prefetchQueries.map(function(e){return o.prefetchQuery(e.queryOptions,t,e.client)}))}},{key:"prefetchQuery",value:function(t,e,r){var o=void 0;if(r){if("string"==typeof r&&!(r=this.clients[r]))throw new Error("[vue-apollo] Missing client '"+r+"' in 'apolloProvider'")}else r=this.defaultClient;if(t.query){var i=t.prefetch,n=void 0===i?"undefined":ee(i);if("undefined"!==n){var s=void 0;if(!(s="function"===n?i(e):i))return Promise.resolve();if("boolean"===n){var a=t.variables;o=void 0!==a?"function"==typeof a?a.call(e):a:void 0}else o=s}}else t={query:t};return"function"==typeof t.query&&(t.query=t.query(e)),new Promise(function(e,i){var n=ft(t,[].concat(ue(ce),["fetchPolicy"]));n.variables=o,n.fetchPolicy="network-only",r.query(n).then(e,i)})}},{key:"getStates",value:function(t){var e=Object.assign({},{exportNamespace:""},t),r={};for(var o in this.clients){var i=this.clients[o].cache.extract();r[""+e.exportNamespace+o]=i}return r}},{key:"exportStates",value:function(t){var e=Object.assign({},{globalName:"__APOLLO_STATE__",attachTo:"window"},t),r=this.getStates(e);return e.attachTo+"."+e.globalName+" = "+JSON.stringify(r)+";"}}]),t}(),ye=[];function de(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return ye.push({component:t,contextCallback:e}),t}"undefined"!=typeof window?window.vueApolloWillPrefetch=de:"undefined"!=typeof global&&(global.vueApolloWillPrefetch=de);var be={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type:Object,required:!0},variables:{type:Object,default:null},fetchPolicy:{type:String,default:"cache-first"},pollInterval:{type:Number,default:0},notifyOnNetworkStatusChange:{type:Boolean,default:!1},context:{type:Object,default:null},skip:{type:Boolean,default:!1},clientId:{type:String,default:void 0},tag:{type:String,default:"div"}},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})}},apollo:{$client:function(){return this.clientId},query:function(){return{query:function(){return this.query},variables:function(){return this.variables},fetchPolicy:this.fetchPolicy,pollInterval:this.pollInterval,notifyOnNetworkStatusChange:this.notifyOnNetworkStatusChange,context:function(){return this.context},skip:function(){return this.skip},manual:!0,result:function(t){var e=t,r=e.errors,o=e.loading,i=e.networkStatus,n=t.error;t=Object.assign({},t),r&&r.length&&((n=new Error("Apollo errors occured ("+r.length+")")).graphQLErrors=r);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),this.result={data:function(t){return Object.keys(t).length>0}(s)?s:void 0,loading:o,error:n,networkStatus:i,times:++this.$_times},this.$emit("result",this.result)},error:function(t){this.result.loading=!1,this.result.error=t,console.log(this.$apollo.queries.query.observer.currentResult()),this.$emit("error",t)}}}},created:function(){this.$_times=0},methods:{getDollarApollo:function(){return this.$apollo},getApolloQuery:function(){return this.$apollo.queries.query}},render:function(t){var e=this.$scopedSlots.default({result:this.result,query:this.$apollo.queries.query});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},ge=0,me={name:"ApolloSubscribeToMore",inject:["getDollarApollo","getApolloQuery"],props:{document:{type:Object,required:!0},variables:{type:Object,default:null},updateQuery:{type:Function,default:null}},watch:{document:"refresh",variables:"refresh"},created:function(){this.$_key="sub_component_"+ge++},mounted:function(){this.refresh()},beforeDestroy:function(){this.destroy()},methods:{destroy:function(){this.$_sub&&this.$_sub.destroy()},refresh:function(){this.destroy(),this.$_sub=this.getDollarApollo().addSmartSubscription(this.$_key,{document:this.document,variables:this.variables,updateQuery:this.updateQuery,linkedQuery:this.getApolloQuery()})}},render:function(t){return null}},_e=["$subscribe"],ke=function(){var t=this.$apolloProvider;if(!this._apolloLaunched&&t){this._apolloLaunched=!0;var e=this.$options.apollo;if(e){for(var r in e.$init||(e.$init=!0,t.defaultOptions&&(e=this.$options.apollo=Object.assign({},t.defaultOptions,e))),$e(this.$apollo,"skipAll",e.$skipAll),$e(this.$apollo,"skipAllQueries",e.$skipAllQueries),$e(this.$apollo,"skipAllSubscriptions",e.$skipAllSubscriptions),$e(this.$apollo,"client",e.$client),$e(this.$apollo,"loadingKey",e.$loadingKey),$e(this.$apollo,"error",e.$error),$e(this.$apollo,"watchLoading",e.$watchLoading),e)"$"!==r.charAt(0)&&this.$apollo.addSmartQuery(r,e[r]);if(e.subscribe&&zt.Vue.util.warn("vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead."),e.$subscribe)for(var o in e.$subscribe)this.$apollo.addSmartSubscription(o,e.$subscribe[o])}}};function $e(t,e,r){void 0!==r&&("function"==typeof r?t.defineReactiveSetter(e,r):t[e]=r)}function we(t,e){if(!we.installed){we.installed=!0,zt.Vue=t;var r=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,o){if(!t)return e;if(!e)return t;for(var i=Object.assign({},ft(t,_e),t.data),n=Object.assign({},ft(e,_e),e.data),s={},a=0;a<_e.length;a++){var u=_e[a];s[u]=r(t[u],e[u])}return Object.assign(s,r(i,n))},Object.defineProperty(t.prototype,"$apollo",{get:function(){return this._apollo||(this._apollo=new pe(this)),this._apollo}});var o=t.version.substr(0,t.version.indexOf("."));t.mixin(ie({},"1"===o?{init:function(){var t=void 0;t=this.$options.apolloProvider?this._apolloProvider=this.$options.apolloProvider:this.$root._apolloProvider,this.$apolloProvider=t}}:{},"2"===o?{inject:{$apolloProvider:{default:null}},data:function(){return this.$options.apollo?{$apolloData:{queries:{},loading:0}}:{}}}:{},{created:ke,destroyed:function(){this._apollo&&(this._apollo.destroy(),this._apollo=null)}})),"2"===o&&(t.component("apollo-query",be),t.component("ApolloQuery",be),t.component("apollo-subscribe-to-more",me),t.component("ApolloSubscribeToMore",me))}}ve.install=we,ve.version="3.0.0-beta.5";var Oe=ve,Se=be,je=me,Ae=null;return"undefined"!=typeof window?Ae=window.Vue:"undefined"!=typeof global&&(Ae=global.Vue),Ae&&Ae.use(ve),t.install=we,t.ApolloProvider=Oe,t.ApolloQuery=Se,t.ApolloSubscribeToMore=je,t.default=ve,t.willPrefetch=de,t}({}); +var VueApollo=function(t){"use strict";var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=200,o="__lodash_hash_undefined__",i=1/0,n=9007199254740991,s="[object Arguments]",a="[object Function]",u="[object GeneratorFunction]",l="[object Symbol]",c=/^\[object .+?Constructor\]$/,h=/^(?:0|[1-9]\d*)$/,p="object"==typeof e&&e&&e.Object===Object&&e,f="object"==typeof self&&self&&self.Object===Object&&self,v=p||f||Function("return this")();function d(t,e){return!!(t?t.length:0)&&function(t,e,r){if(e!=e)return function(t,e,r,o){var i=t.length,n=r+(o?1:-1);for(;o?n--:++n-1}function y(t,e,r){for(var o=-1,i=t?t.length:0;++o-1},K.prototype.set=function(t,e){var r=this.__data__,o=H(r,t);return o<0?r.push([t,e]):r[o][1]=e,this},I.prototype.clear=function(){this.__data__={hash:new V,map:new(R||K),string:new V}},I.prototype.delete=function(t){return U(this,t).delete(t)},I.prototype.get=function(t){return U(this,t).get(t)},I.prototype.has=function(t){return U(this,t).has(t)},I.prototype.set=function(t,e){return U(this,t).set(t,e),this},F.prototype.add=F.prototype.push=function(t){return this.__data__.set(t,o),this},F.prototype.has=function(t){return this.__data__.has(t)};var X=C?$(C,Object):ht,Y=C?function(t){for(var e=[];t;)g(e,X(t)),t=E(t);return e}:ht;function Z(t){return nt(t)||rt(t)||!!(T&&t&&t[T])}function tt(t,e){return!!(e=null==e?n:e)&&("number"==typeof t||h.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=n}(t.length)&&!at(t)}function at(t){var e=ut(t)?x.call(t):"";return e==a||e==u}function ut(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function lt(t){return!!t&&"object"==typeof t}function ct(t){return st(t)?W(t,!0):J(t)}function ht(){return[]}var pt=(ot=function(t,e){return null==t?{}:(e=b(function t(e,r,o,i,n){var s=-1,a=e.length;for(o||(o=Z),n||(n=[]);++s0&&o(u)?r>1?t(u,r-1,o,i,n):g(n,u):i||(n[n.length]=u)}return n}(e,1),et),function(t,e){return function(t,e,r){for(var o=-1,i=e.length,n={};++o=r&&(a=_,u=!1,e=new F(e));t:for(;++s=e||r<0||h&&t-l>=n}function d(){var t=At();if(v(t))return y(t);a=setTimeout(d,function(t){var r=e-(t-u);return h?jt(r,n-(t-l)):r}(t))}function y(t){return a=void 0,p&&o?f(t):(o=i=void 0,s)}function b(){var t=At(),r=v(t);if(o=arguments,i=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(d,e),c?f(t):s}(u);if(h)return a=setTimeout(d,e),f(u)}return void 0===a&&(a=setTimeout(d,e)),s}return e=qt(e)||0,xt(r)&&(c=!!r.leading,n=(h="maxWait"in r)?St(qt(r.maxWait)||0,e):n,p="trailing"in r?!!r.trailing:p),b.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=i=a=void 0},b.flush=function(){return void 0===a?s:y(At())},b}function xt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function qt(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ot.call(t)==dt}(t))return vt;if(xt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=xt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(yt,"");var r=gt.test(t);return r||mt.test(t)?_t(t.slice(2),r?2:8):bt.test(t)?vt:+t}var Qt=function(t,e,r){var o=!0,i=!0;if("function"!=typeof t)throw new TypeError(ft);return xt(r)&&(o="leading"in r?!!r.leading:o,i="trailing"in r?!!r.trailing:i),Pt(t,e,{leading:o,maxWait:e,trailing:i})},Et="Expected a function",Lt=NaN,Dt="[object Symbol]",Tt=/^\s+|\s+$/g,Ct=/^[-+]0x[0-9a-f]+$/i,Mt=/^0b[01]+$/i,Rt=/^0o[0-7]+$/i,Nt=parseInt,Vt="object"==typeof e&&e&&e.Object===Object&&e,Kt="object"==typeof self&&self&&self.Object===Object&&self,It=Vt||Kt||Function("return this")(),Ft=Object.prototype.toString,Wt=Math.max,Ht=Math.min,Gt=function(){return It.Date.now()};function Jt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Bt(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ft.call(t)==Dt}(t))return Lt;if(Jt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Jt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(Tt,"");var r=Mt.test(t);return r||Rt.test(t)?Nt(t.slice(2),r?2:8):Ct.test(t)?Lt:+t}var Ut=function(t,e,r){var o,i,n,s,a,u,l=0,c=!1,h=!1,p=!0;if("function"!=typeof t)throw new TypeError(Et);function f(e){var r=o,n=i;return o=i=void 0,l=e,s=t.apply(n,r)}function v(t){var r=t-u;return void 0===u||r>=e||r<0||h&&t-l>=n}function d(){var t=Gt();if(v(t))return y(t);a=setTimeout(d,function(t){var r=e-(t-u);return h?Ht(r,n-(t-l)):r}(t))}function y(t){return a=void 0,p&&o?f(t):(o=i=void 0,s)}function b(){var t=Gt(),r=v(t);if(o=arguments,i=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(d,e),c?f(t):s}(u);if(h)return a=setTimeout(d,e),f(u)}return void 0===a&&(a=setTimeout(d,e)),s}return e=Bt(e)||0,Jt(r)&&(c=!!r.leading,n=(h="maxWait"in r)?Wt(Bt(r.maxWait)||0,e):n,p="trailing"in r?!!r.trailing:p),b.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=i=a=void 0},b.flush=function(){return void 0===a?s:y(Gt())},b},zt={};function Xt(t){return function(e,r){return"number"==typeof r?t(e,r):t(e,r.wait,r)}}var Yt=Xt(Qt),Zt=Xt(Ut);function te(t,e){for(;"function"==typeof t;)t=t.call(e);return t}var ee="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},re=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},oe=function(){function t(t,e){for(var r=0;r3&&void 0!==arguments[3])||arguments[3];if(re(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=r,this.options=Object.assign({},o),this._skip=!1,this._watchers=[],this._destroyed=!1,"function"==typeof this.options.query){var s=this.options.query.bind(this.vm);this.options.query=s(),this._watchers.push(this.vm.$watch(s,function(t){i.options.query=t,i.refresh()}))}if("function"==typeof this.options.document){var a=this.options.document.bind(this.vm);this.options.document=a(),this._watchers.push(this.vm.$watch(a,function(t){i.options.document=t,i.refresh()}))}if("function"==typeof this.options.context){var u=this.options.context.bind(this.vm);this.options.context=u(),this._watchers.push(this.vm.$watch(u,function(t){i.options.context=t,i.refresh()}))}this.vm.$isServer&&(this.options.fetchPolicy="cache-first"),n&&this.autostart()}return oe(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._watchers.push(this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0})):this.options.skip?this._skip=!0:this.start()}},{key:"skipChanged",value:function(t,e){t!==e&&(this.skip=t)}},{key:"refresh",value:function(){this._skip||(this.stop(),this.start())}},{key:"start",value:function(){var t=this;if(this.starting=!0,"function"==typeof this.options.variables){var e=this.executeApollo.bind(this);e=this.options.throttle?Yt(e,this.options.throttle):e,e=this.options.debounce?Zt(e,this.options.debounce):e,this.unwatchVariables=this.vm.$watch(function(){return t.options.variables.call(t.vm)},e,{immediate:!0})}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){this.unwatchVariables&&(this.unwatchVariables(),this.unwatchVariables=null),this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=pt(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(){throw new Error("Not implemented")}},{key:"errorHandler",value:function(){for(var t,e,r,o=arguments.length,i=Array(o),n=0;n3&&void 0!==arguments[3])||arguments[3];(re(this,e),o.query)||(o={query:o});t.$data.$apolloData&&!t.$data.$apolloData.queries[r]&&t.$set(t.$data.$apolloData.queries,r,{loading:!1});var n=ae(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r,o,i));return n.type="query",n.vueApolloSpecialKeys=ce,n._loading=!1,n}return se(e,le),oe(e,[{key:"stop",value:function(){ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t)),this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)}));var r=this.maySetLoading();r.loading||this.nextResult(r),ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"maySetLoading",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.observer.currentResult();return(t||e.loading)&&(this.loading||this.applyLoadingModifier(1),this.loading=!0),e}},{key:"nextResult",value:function(t){var e=t.data;t.loading||this.loadingDone();var r="function"==typeof this.options.result;void 0===e||(this.options.manual?r||console.error(this.key+" query must have a 'result' hook in manual mode"):"function"==typeof this.options.update?this.vm.$set(this.vm.$apolloData.data,this.key,this.options.update.call(this.vm,e)):void 0===e[this.key]?console.error("Missing "+this.key+" attribute on result",e):this.vm.$set(this.vm.$apolloData.data,this.key,e[this.key])),r&&this.options.result.call(this.vm,t)}},{key:"catchError",value:function(t){ne(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone()}},{key:"watchLoading",value:function(){for(var t,e,r,o=arguments.length,i=Array(o),n=0;n0&&void 0!==arguments[0]?arguments[0]:null;if(!t||!t.client){if("object"===ee(this.client))return this.client;if(this.client){if(this.provider.clients){var e=this.provider.clients[this.client];if(!e)throw new Error("[vue-apollo] Missing client '"+this.client+"' in 'apolloProvider'");return e}throw new Error("[vue-apollo] Missing 'clients' options in 'apolloProvider'")}return this.provider.defaultClient}var r=this.provider.clients[t.client];if(!r)throw new Error("[vue-apollo] Missing client '"+t.client+"' in 'apolloProvider'");return r}},{key:"watchQuery",value:function(t){var e=this,r=this.getClient(t).watchQuery(t),o=r.subscribe.bind(r);return r.subscribe=function(t){var r=o(t);return e._apolloSubscriptions.push(r),r},r}},{key:"mutate",value:function(t){return this.getClient(t).mutate(t)}},{key:"subscribe",value:function(t){var e=this;if(!this.vm.$isServer){var r=this.getClient(t).subscribe(t),o=r.subscribe.bind(r);return r.subscribe=function(t){var r=o(t);return e._apolloSubscriptions.push(r),r},r}}},{key:"addSmartQuery",value:function(t,e){var r=this;e=te(e,this.vm);var o=this.queries[t]=new he(this.vm,t,e,!1);if(o.autostart(),!this.vm.$isServer){var i=e.subscribeToMore;i&&(Array.isArray(i)?i.forEach(function(e,i){r.addSmartSubscription(""+t+i,ie({},e,{linkedQuery:o}))}):this.addSmartSubscription(t,ie({},i,{linkedQuery:o})))}return o}},{key:"addSmartSubscription",value:function(t,e){if(!this.vm.$isServer){e=te(e,this.vm);var r=this.subscriptions[t]=new pe(this.vm,t,e,!1);return r.autostart(),r}}},{key:"defineReactiveSetter",value:function(t,e){var r=this;this._watchers.push(this.vm.$watch(e,function(e){r[t]=e},{immediate:!0}))}},{key:"destroy",value:function(){var t=!0,e=!1,r=void 0;try{for(var o,i=this._watchers[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,r=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw r}}for(var n in this.queries)this.queries[n].destroy();for(var s in this.subscriptions)this.subscriptions[s].destroy();this._apolloSubscriptions.forEach(function(t){t.unsubscribe()}),this._apolloSubscriptions=null,this.vm=null}},{key:"provider",get:function(){return this.vm.$apolloProvider}},{key:"loading",get:function(){return this.vm.$data.$apolloData&&0!==this.vm.$data.$apolloData.loading}},{key:"skipAllQueries",set:function(t){for(var e in this.queries)this.queries[e].skip=t}},{key:"skipAllSubscriptions",set:function(t){for(var e in this.subscriptions)this.subscriptions[e].skip=t}},{key:"skipAll",set:function(t){this.skipAllQueries=t,this.skipAllSubscriptions=t}}]),t}(),ve=function(){function t(e){if(re(this,t),!e)throw new Error("Options argument required");this.clients=e.clients||{},this.clients.defaultClient=this.defaultClient=e.defaultClient,this.defaultOptions=e.defaultOptions,this.watchLoading=e.watchLoading,this.errorHandler=e.errorHandler,this.prefetchQueries=[]}return oe(t,[{key:"provide",value:function(){return function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:"$apolloProvider",this)}},{key:"addQueryToPrefetch",value:function(t,e){this.prefetchQueries.push({queryOptions:t,client:e})}},{key:"prefetchComponent",value:function(t,e){var r;r=t;var o=(t=zt.Vue.util.mergeOptions({},r)).apollo;if(o){var i=o.$client;for(var n in o){var s=o[n];"$"===n.charAt(0)||s.query&&(void 0!==s.ssr&&!s.ssr||void 0===s.prefetch||!s.prefetch)||this.addQueryToPrefetch(s,s.client||i)}}}},{key:"prefetchComponents",value:function(t){var e=!0,r=!1,o=void 0;try{for(var i,n=t[Symbol.iterator]();!(e=(i=n.next()).done);e=!0){var s=i.value;this.prefetchComponent(s)}}catch(t){r=!0,o=t}finally{try{!e&&n.return&&n.return()}finally{if(r)throw o}}}},{key:"prefetchAll",value:function(t,e,r){var o=this;r||!e||Array.isArray(e)||(r=e,e=void 0);var i=Object.assign({},{includeGlobal:!0},r);return e&&this.prefetchComponents(e),i.includeGlobal&&this.prefetchComponents(de.filter(function(e){e.component;var r=e.contextCallback,o=!0;return"function"==typeof r&&(o=!!r(t)),o}).map(function(t){return t.component}),t),Promise.all(this.prefetchQueries.map(function(e){return o.prefetchQuery(e.queryOptions,t,e.client)}))}},{key:"prefetchQuery",value:function(t,e,r){var o=void 0;if(r){if("string"==typeof r&&!(r=this.clients[r]))throw new Error("[vue-apollo] Missing client '"+r+"' in 'apolloProvider'")}else r=this.defaultClient;if(t.query){var i=t.prefetch,n=void 0===i?"undefined":ee(i);if("undefined"!==n){var s=void 0;if(!(s="function"===n?i(e):i))return Promise.resolve();if("boolean"===n){var a=t.variables;o=void 0!==a?"function"==typeof a?a.call(e):a:void 0}else o=s}}else t={query:t};return"function"==typeof t.query&&(t.query=t.query(e)),new Promise(function(e,i){var n=pt(t,[].concat(ue(ce),["fetchPolicy"]));n.variables=o,n.fetchPolicy="network-only",r.query(n).then(e,i)})}},{key:"getStates",value:function(t){var e=Object.assign({},{exportNamespace:""},t),r={};for(var o in this.clients){var i=this.clients[o].cache.extract();r[""+e.exportNamespace+o]=i}return r}},{key:"exportStates",value:function(t){var e=Object.assign({},{globalName:"__APOLLO_STATE__",attachTo:"window"},t),r=this.getStates(e);return e.attachTo+"."+e.globalName+" = "+JSON.stringify(r)+";"}}]),t}(),de=[];function ye(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return de.push({component:t,contextCallback:e}),t}"undefined"!=typeof window?window.vueApolloWillPrefetch=ye:"undefined"!=typeof global&&(global.vueApolloWillPrefetch=ye);var be={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type:Object,required:!0},variables:{type:Object,default:null},fetchPolicy:{type:String,default:"cache-first"},pollInterval:{type:Number,default:0},notifyOnNetworkStatusChange:{type:Boolean,default:!1},context:{type:Object,default:null},skip:{type:Boolean,default:!1},clientId:{type:String,default:void 0},tag:{type:String,default:"div"}},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})}},apollo:{$client:function(){return this.clientId},query:function(){return{query:function(){return this.query},variables:function(){return this.variables},fetchPolicy:this.fetchPolicy,pollInterval:this.pollInterval,notifyOnNetworkStatusChange:this.notifyOnNetworkStatusChange,context:function(){return this.context},skip:function(){return this.skip},manual:!0,result:function(t){var e=t,r=e.errors,o=e.loading,i=e.networkStatus,n=t.error;t=Object.assign({},t),r&&r.length&&((n=new Error("Apollo errors occured ("+r.length+")")).graphQLErrors=r);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),this.result={data:function(t){return Object.keys(t).length>0}(s)?s:void 0,loading:o,error:n,networkStatus:i,times:++this.$_times},this.$emit("result",this.result)},error:function(t){this.result.loading=!1,this.result.error=t,console.log(this.$apollo.queries.query.observer.currentResult()),this.$emit("error",t)}}}},created:function(){this.$_times=0},methods:{getDollarApollo:function(){return this.$apollo},getApolloQuery:function(){return this.$apollo.queries.query}},render:function(t){var e=this.$scopedSlots.default({result:this.result,query:this.$apollo.queries.query});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},ge=0,me={name:"ApolloSubscribeToMore",inject:["getDollarApollo","getApolloQuery"],props:{document:{type:Object,required:!0},variables:{type:Object,default:null},updateQuery:{type:Function,default:null}},watch:{document:"refresh",variables:"refresh"},created:function(){this.$_key="sub_component_"+ge++},mounted:function(){this.refresh()},beforeDestroy:function(){this.destroy()},methods:{destroy:function(){this.$_sub&&this.$_sub.destroy()},refresh:function(){this.destroy(),this.$_sub=this.getDollarApollo().addSmartSubscription(this.$_key,{document:this.document,variables:this.variables,updateQuery:this.updateQuery,linkedQuery:this.getApolloQuery()})}},render:function(t){return null}},_e={props:{mutation:{type:Object,required:!0},variables:{type:Object,default:void 0},optimisticResponse:{type:Object,default:void 0},update:{type:Function,default:void 0},refetchQueries:{type:Function,default:void 0},tag:{type:String,default:"div"}},data:function(){return{loading:!1,error:null}},methods:{mutate:function(t){var e,r=this;return(e=regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.loading=!0,r.error=null,e.prev=2,e.next=5,r.$apollo.mutate(ie({mutation:r.mutation,variables:r.variables,optimisticResponse:r.optimisticResponse,update:r.update,refetchQueries:r.refetchQueries},t));case 5:r.$emit("done"),e.next=12;break;case 8:e.prev=8,e.t0=e.catch(2),r.error=e.t0,r.$emit("error",e.t0);case 12:r.loading=!1;case 13:case"end":return e.stop()}},e,r,[[2,8]])}),function(){var t=e.apply(this,arguments);return new Promise(function(e,r){return function o(i,n){try{var s=t[i](n),a=s.value}catch(t){return void r(t)}if(!s.done)return Promise.resolve(a).then(function(t){o("next",t)},function(t){o("throw",t)});e(a)}("next")})})()}},render:function(t){var e=this.$scopedSlots.default({mutate:this.mutate,loading:this.loading,error:this.error});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},$e=["$subscribe"],ke=function(){var t=this,e=this.$apolloProvider;if(!this._apolloLaunched&&e){this._apolloLaunched=!0;var r=this.$options.apollo;if(r){r.$init||(r.$init=!0,e.defaultOptions&&(r=this.$options.apollo=Object.assign({},e.defaultOptions,r))),we(this.$apollo,"skipAll",r.$skipAll),we(this.$apollo,"skipAllQueries",r.$skipAllQueries),we(this.$apollo,"skipAllSubscriptions",r.$skipAllSubscriptions),we(this.$apollo,"client",r.$client),we(this.$apollo,"loadingKey",r.$loadingKey),we(this.$apollo,"error",r.$error),we(this.$apollo,"watchLoading",r.$watchLoading);var o=function(e){"$"!==e.charAt(0)&&(Object.defineProperty(t,e,{get:function(){return t.$apolloData.data[e]},enumerable:!0,configurable:!0}),t.$apollo.addSmartQuery(e,r[e]))};for(var i in r)o(i);if(r.subscribe&&zt.Vue.util.warn("vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead."),r.$subscribe)for(var i in r.$subscribe)this.$apollo.addSmartSubscription(i,r.$subscribe[i])}}};function we(t,e,r){void 0!==r&&("function"==typeof r?t.defineReactiveSetter(e,r):t[e]=r)}function Oe(t,e){if(!Oe.installed){Oe.installed=!0,zt.Vue=t;var r=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,o){if(!t)return e;if(!e)return t;for(var i=Object.assign({},pt(t,$e),t.data),n=Object.assign({},pt(e,$e),e.data),s={},a=0;a<$e.length;a++){var u=$e[a];s[u]=r(t[u],e[u])}return Object.assign(s,r(i,n))},Object.defineProperty(t.prototype,"$apollo",{get:function(){return this._apollo||(this._apollo=new fe(this)),this._apollo}});var o=t.version.substr(0,t.version.indexOf("."));t.mixin(ie({},"1"===o?{init:function(){var t=void 0;t=this.$options.apolloProvider?this._apolloProvider=this.$options.apolloProvider:this.$root._apolloProvider,this.$apolloProvider=t}}:{},"2"===o?{inject:{$apolloProvider:{default:null}},data:function(){return this.$options.apollo?{$apolloData:{queries:{},loading:0,data:{}}}:{}}}:{},{created:ke,destroyed:function(){this._apollo&&(this._apollo.destroy(),this._apollo=null)}})),"2"===o&&(t.component("apollo-query",be),t.component("ApolloQuery",be),t.component("apollo-subscribe-to-more",me),t.component("ApolloSubscribeToMore",me),t.component("apollo-mutation",_e),t.component("ApolloMutation",_e))}}ve.install=Oe,ve.version="3.0.0-beta.6";var Se=ve,je=be,Ae=me,Pe=_e,xe=null;return"undefined"!=typeof window?xe=window.Vue:"undefined"!=typeof global&&(xe=global.Vue),xe&&xe.use(ve),t.install=Oe,t.ApolloProvider=Se,t.ApolloQuery=je,t.ApolloSubscribeToMore=Ae,t.ApolloMutation=Pe,t.default=ve,t.willPrefetch=ye,t}({}); diff --git a/dist/vue-apollo.umd.js b/dist/vue-apollo.umd.js index ed9051f..63a1b16 100644 --- a/dist/vue-apollo.umd.js +++ b/dist/vue-apollo.umd.js @@ -2354,7 +2354,34 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol +var asyncToGenerator = function (fn) { + return function () { + var gen = fn.apply(this, arguments); + return new Promise(function (resolve, reject) { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + return Promise.resolve(value).then(function (value) { + step("next", value); + }, function (err) { + step("throw", err); + }); + } + } + + return step("next"); + }); + }; +}; var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { @@ -2838,12 +2865,14 @@ var SmartQuery = function (_SmartApollo) { if (typeof data === 'undefined') { // No result - } else if (typeof this.options.update === 'function') { - this.vm[this.key] = this.options.update.call(this.vm, data); - } else if (data[this.key] === undefined && !this.options.manual) { - console.error('Missing ' + this.key + ' attribute on result', data); } else if (!this.options.manual) { - this.vm[this.key] = data[this.key]; + if (typeof this.options.update === 'function') { + this.vm.$set(this.vm.$apolloData.data, this.key, this.options.update.call(this.vm, data)); + } else if (data[this.key] === undefined) { + console.error('Missing ' + this.key + ' attribute on result', data); + } else { + this.vm.$set(this.vm.$apolloData.data, this.key, data[this.key]); + } } else if (!hasResultCallback) { console.error(this.key + ' query must have a \'result\' hook in manual mode'); } @@ -3758,9 +3787,113 @@ var CApolloSubscribeToMore = { } }; +var CApolloMutation = { + props: { + mutation: { + type: Object, + required: true + }, + + variables: { + type: Object, + default: undefined + }, + + optimisticResponse: { + type: Object, + default: undefined + }, + + update: { + type: Function, + default: undefined + }, + + refetchQueries: { + type: Function, + default: undefined + }, + + tag: { + type: String, + default: 'div' + } + }, + + data: function data() { + return { + loading: false, + error: null + }; + }, + + + methods: { + mutate: function mutate(options) { + var _this = this; + + return asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _this.loading = true; + _this.error = null; + _context.prev = 2; + _context.next = 5; + return _this.$apollo.mutate(_extends({ + mutation: _this.mutation, + variables: _this.variables, + optimisticResponse: _this.optimisticResponse, + update: _this.update, + refetchQueries: _this.refetchQueries + }, options)); + + case 5: + _this.$emit('done'); + _context.next = 12; + break; + + case 8: + _context.prev = 8; + _context.t0 = _context['catch'](2); + + _this.error = _context.t0; + _this.$emit('error', _context.t0); + + case 12: + _this.loading = false; + + case 13: + case 'end': + return _context.stop(); + } + } + }, _callee, _this, [[2, 8]]); + }))(); + } + }, + + render: function render(h) { + var result = this.$scopedSlots.default({ + mutate: this.mutate, + loading: this.loading, + error: this.error + }); + if (Array.isArray(result)) { + result = result.concat(this.$slots.default); + } else { + result = [result].concat(this.$slots.default); + } + return h(this.tag, result); + } +}; + var keywords = ['$subscribe']; var launch = function launch() { + var _this = this; + var apolloProvider = this.$apolloProvider; if (this._apolloLaunched || !apolloProvider) return; @@ -3788,10 +3921,22 @@ var launch = function launch() { defineReactiveSetter(this.$apollo, 'watchLoading', apollo.$watchLoading); // watchQuery - for (var key in apollo) { + + var _loop = function _loop(key) { if (key.charAt(0) !== '$') { - this.$apollo.addSmartQuery(key, apollo[key]); + Object.defineProperty(_this, key, { + get: function get$$1() { + return _this.$apolloData.data[key]; + }, + enumerable: true, + configurable: true + }); + _this.$apollo.addSmartQuery(key, apollo[key]); } + }; + + for (var key in apollo) { + _loop(key); } if (apollo.subscribe) { @@ -3799,8 +3944,8 @@ var launch = function launch() { } if (apollo.$subscribe) { - for (var _key in apollo.$subscribe) { - this.$apollo.addSmartSubscription(_key, apollo.$subscribe[_key]); + for (var key in apollo.$subscribe) { + this.$apollo.addSmartSubscription(key, apollo.$subscribe[key]); } } } @@ -3871,7 +4016,8 @@ function install(Vue, options) { return this.$options.apollo ? { '$apolloData': { queries: {}, - loading: 0 + loading: 0, + data: {} } } : {}; } @@ -3893,19 +4039,22 @@ function install(Vue, options) { Vue.component('ApolloQuery', CApolloQuery); Vue.component('apollo-subscribe-to-more', CApolloSubscribeToMore); Vue.component('ApolloSubscribeToMore', CApolloSubscribeToMore); + Vue.component('apollo-mutation', CApolloMutation); + Vue.component('ApolloMutation', CApolloMutation); } } ApolloProvider.install = install; // eslint-disable-next-line no-undef -ApolloProvider.version = "3.0.0-beta.5"; +ApolloProvider.version = "3.0.0-beta.6"; // Apollo provider var ApolloProvider$1 = ApolloProvider; // Components var ApolloQuery = CApolloQuery; var ApolloSubscribeToMore = CApolloSubscribeToMore; +var ApolloMutation = CApolloMutation; // Auto-install var GlobalVue = null; @@ -3922,6 +4071,7 @@ exports.install = install; exports.ApolloProvider = ApolloProvider$1; exports.ApolloQuery = ApolloQuery; exports.ApolloSubscribeToMore = ApolloSubscribeToMore; +exports.ApolloMutation = ApolloMutation; exports.default = ApolloProvider; exports.willPrefetch = willPrefetch; diff --git a/package.json b/package.json index 28e7f51..8a9d948 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-apollo", - "version": "3.0.0-beta.5", + "version": "3.0.0-beta.6", "description": "Use Apollo and GraphQL with Vue.js", "main": "dist/vue-apollo.umd.js", "module": "dist/vue-apollo.esm.js",