diff --git a/dist/vue-apollo.esm.js b/dist/vue-apollo.esm.js index b202250c..780c6b3b 100644 --- a/dist/vue-apollo.esm.js +++ b/dist/vue-apollo.esm.js @@ -1975,14 +1975,16 @@ function install(Vue, options) { }; // Lazy creation - Object.defineProperty(Vue.prototype, '$apollo', { - get: function get$$1() { - if (!this._apollo) { - this._apollo = new DollarApollo(this); + if (!Vue.prototype.hasOwnProperty('$apollo')) { + Object.defineProperty(Vue.prototype, '$apollo', { + get: function get$$1() { + if (!this._apollo) { + this._apollo = new DollarApollo(this); + } + return this._apollo; } - return this._apollo; - } - }); + }); + } var vueVersion = Vue.version.substr(0, Vue.version.indexOf('.')); diff --git a/dist/vue-apollo.min.js b/dist/vue-apollo.min.js index ac29251c..8dab1920 100644 --- a/dist/vue-apollo.min.js +++ b/dist/vue-apollo.min.js @@ -1 +1 @@ -var VueApollo=function(t){"use strict";function e(t,e,i,o){var r,n=0;return"boolean"!=typeof e&&(o=i,i=e,e=void 0),function(){var s=this,a=Number(new Date)-n,l=arguments;function u(){n=Number(new Date),i.apply(s,l)}o&&!r&&u(),r&&clearTimeout(r),void 0===o&&a>t?u():!0!==e&&(r=setTimeout(o?function(){r=void 0}:u,void 0===o?t-a:t))}}var i="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},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var i=0;i3&&void 0!==arguments[3])||arguments[3];o(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=i,this.initialOptions=r,this.options=Object.assign({},r),this._skip=!1,this._watchers=[],this._destroyed=!1,this.vm.$isServer&&(this.options.fetchPolicy="cache-first"),n&&this.autostart()}return r(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._skipWatcher=this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0,deep:this.options.deep}):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.initialOptions.query){var e=this.initialOptions.query.bind(this.vm);this.options.query=e(),this._watchers.push(this.vm.$watch(e,function(e){t.options.query=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.initialOptions.document){var i=this.initialOptions.document.bind(this.vm);this.options.document=i(),this._watchers.push(this.vm.$watch(i,function(e){t.options.document=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.initialOptions.context){var o=this.initialOptions.context.bind(this.vm);this.options.context=o(),this._watchers.push(this.vm.$watch(o,function(e){t.options.context=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.options.variables){var r=this.executeApollo.bind(this);r=this.options.throttle?f(r,this.options.throttle):r,r=this.options.debounce?d(r,this.options.debounce):r,this._watchers.push(this.vm.$watch(function(){return t.options.variables.call(t.vm)},r,{immediate:!0,deep:this.options.deep}))}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){var t=!0,e=!1,i=void 0;try{for(var o,r=this._watchers[Symbol.iterator]();!(t=(o=r.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,i=t}finally{try{!t&&r.return&&r.return()}finally{if(e)throw i}}this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=y(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(t){var e=t.error;e&&b(e)}},{key:"callHandlers",value:function(t){for(var e=!1,i=arguments.length,o=Array(i>1?i-1:0),r=1;r3&&void 0!==arguments[3])||arguments[3];(o(this,e),r.query)||(r={query:r});t.$data.$apolloData&&!t.$data.$apolloData.queries[i]&&t.$set(t.$data.$apolloData.queries,i,{loading:!1});var s=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i,r,n));return s.type="query",s.vueApolloSpecialKeys=m,s._loading=!1,r.manual||(s.hasDataField=s.vm.$data.hasOwnProperty(i),s.hasDataField?Object.defineProperty(s.vm.$data.$apolloData.data,i,{get:function(){return s.vm.$data[i]},enumerable:!0,configurable:!0}):Object.defineProperty(s.vm.$data,i,{get:function(){return s.vm.$data.$apolloData.data[i]},enumerable:!0,configurable:!0})),s}return a(e,g),r(e,[{key:"stop",value:function(){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){if(this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t))),this.startQuerySubscription(),"no-cache"!==this.options.fetchPolicy){var i=this.maySetLoading();i.loading||this.nextResult(i)}s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"startQuerySubscription",value:function(){this.sub&&!this.sub.closed||(this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)}))}},{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){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"nextResult",this).call(this,t);var i=t.data;t.loading||this.loadingDone();var o="function"==typeof this.options.result;void 0===i||(this.options.manual?o||console.error(this.key+" query must have a 'result' hook in manual mode"):"function"==typeof this.options.update?this.setData(this.options.update.call(this.vm,i)):void 0===i[this.key]&&Object.keys(i).length?console.error("Missing "+this.key+" attribute on result",i):this.setData(i[this.key])),o&&this.options.result.call(this.vm,t)}},{key:"setData",value:function(t){this.vm.$set(this.hasDataField?this.vm.$data:this.vm.$data.$apolloData.data,this.key,t)}},{key:"catchError",value:function(t){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone(),this.nextResult(this.observer.currentResult()),this.resubscribeToQuery()}},{key:"resubscribeToQuery",value:function(){var t=this.observer.getLastError(),e=this.observer.getLastResult();this.observer.resetLastResults(),this.startQuerySubscription(),Object.assign(this.observer,{lastError:t,lastResult:e})}},{key:"watchLoading",value:function(){for(var t=arguments.length,e=Array(t),i=0;i0&&void 0!==arguments[0]?arguments[0]:null;if(!t||!t.client){if("object"===i(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 o=this.provider.clients[t.client];if(!o)throw new Error("[vue-apollo] Missing client '"+t.client+"' in 'apolloProvider'");return o}},{key:"watchQuery",value:function(t){var e=this,i=this.getClient(t).watchQuery(t),o=i.subscribe.bind(i);return i.subscribe=function(t){var i=o(t);return e._apolloSubscriptions.push(i),i},i}},{key:"mutate",value:function(t){return this.getClient(t).mutate(t)}},{key:"subscribe",value:function(t){var e=this;if(!this.vm.$isServer){var i=this.getClient(t).subscribe(t),o=i.subscribe.bind(i);return i.subscribe=function(t){var i=o(t);return e._apolloSubscriptions.push(i),i},i}}},{key:"addSmartQuery",value:function(t,e){var i=this,o=v(e,this.vm),r=this.vm.$options.apollo,s=this.provider.defaultOptions,a=void 0;if(r&&r.$query&&(a=r.$query),r&&r.$query||!s||!s.$query||(a=s.$query),a)for(var l in a)void 0===o[l]&&(o[l]=a[l]);var u=this.queries[t]=new $(this.vm,t,o,!1);if(u.autostart(),!this.vm.$isServer){var h=o.subscribeToMore;h&&(Array.isArray(h)?h.forEach(function(e,o){i.addSmartSubscription(""+t+o,n({},e,{linkedQuery:u}))}):this.addSmartSubscription(t,n({},h,{linkedQuery:u})))}return u}},{key:"addSmartSubscription",value:function(t,e){if(!this.vm.$isServer){e=v(e,this.vm);var i=this.subscriptions[t]=new k(this.vm,t,e,!1);return i.autostart(),i}}},{key:"defineReactiveSetter",value:function(t,e,i){var o=this;this._watchers.push(this.vm.$watch(e,function(e){o[t]=e},{immediate:!0,deep:i}))}},{key:"destroy",value:function(){var t=!0,e=!1,i=void 0;try{for(var o,r=this._watchers[Symbol.iterator]();!(t=(o=r.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,i=t}finally{try{!t&&r.return&&r.return()}finally{if(e)throw i}}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 0!==this.vm.$data.$apolloData.loading}},{key:"data",get:function(){return this.vm.$data.$apolloData.data}},{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}(),_=function(){function t(e){if(o(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 r(t,[{key:"provide",value:function(){return function(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,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 i;i=t;var o=(t=c.Vue.util.mergeOptions({},i)).apollo;if(o){var r=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||r)}}}},{key:"prefetchComponents",value:function(t){var e=!0,i=!1,o=void 0;try{for(var r,n=t[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var s=r.value;this.prefetchComponent(s)}}catch(t){i=!0,o=t}finally{try{!e&&n.return&&n.return()}finally{if(i)throw o}}}},{key:"prefetchAll",value:function(t,e,i){var o=this;i||!e||Array.isArray(e)||(i=e,e=void 0);var r=Object.assign({},{includeGlobal:!0},i);return e&&this.prefetchComponents(e),r.includeGlobal&&this.prefetchComponents(w.filter(function(e){e.component;var i=e.contextCallback,o=!0;return"function"==typeof i&&(o=!!i(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,o){var r=void 0;if(o){if("string"==typeof o&&!(o=this.clients[o]))throw new Error("[vue-apollo] Missing client '"+o+"' in 'apolloProvider'")}else o=this.defaultClient;if(t.query){var n=t.prefetch,s=void 0===n?"undefined":i(n);if("undefined"!==s){var a=void 0;if(!(a="function"===s?n(e):n))return Promise.resolve();if("boolean"===s){var l=t.variables;r=void 0!==l?"function"==typeof l?l.call(e):l:void 0}else r=a}}else t={query:t};return"function"==typeof t.query&&(t.query=t.query(e)),new Promise(function(e,i){var n=y(t,[].concat(h(m),["fetchPolicy"]));n.variables=r,n.fetchPolicy="network-only",o.query(n).then(e,i)})}},{key:"getStates",value:function(t){var e=Object.assign({},{exportNamespace:""},t),i={};for(var o in this.clients){var r=this.clients[o].cache.extract();i[""+e.exportNamespace+o]=r}return i}},{key:"exportStates",value:function(t){var e=Object.assign({},{globalName:"__APOLLO_STATE__",attachTo:"window"},t),i=this.getStates(e);return e.attachTo+"."+e.globalName+" = "+JSON.stringify(i)+";"}}]),t}(),w=[];function S(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return w.push({component:t,contextCallback:e}),t}"undefined"!=typeof window?window.vueApolloWillPrefetch=S:"undefined"!=typeof global&&(global.vueApolloWillPrefetch=S);var A={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type: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},skip:{type:Boolean,default:!1},clientId:{type:String,default:void 0},deep:{type:Boolean,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},deep:this.deep,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 occured ("+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),this.result={data:function(t){return Object.keys(t).length>0}(s)?s:void 0,loading:o,error:n,networkStatus:r},this.times=++this.$_times,this.$emit("result",this.result)},error:function(t){this.result.loading=!1,this.result.error=t,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,times:this.times,query:this.$apollo.queries.query,isLoading:this.$apolloData.loading,gqlError:this.result&&this.result.error&&this.result.error.gqlError});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},q=0,P={name:"ApolloSubscribeToMore",inject:["getDollarApollo","getApolloQuery"],props:{document:{type:Object,required:!0},variables:{type:Object,default:void 0},updateQuery:{type:Function,default:void 0}},watch:{document:"refresh",variables:"refresh"},created:function(){this.$_key="sub_component_"+q++},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}},Q={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=this;this.loading=!0,this.error=null,this.$apollo.mutate(n({mutation:this.mutation,variables:this.variables,optimisticResponse:this.optimisticResponse,update:this.update,refetchQueries:this.refetchQueries},t)).then(function(t){e.$emit("done",t),e.loading=!1}).catch(function(t){b(t),e.error=t,e.$emit("error",t),e.loading=!1})}},render:function(t){var e=this.$scopedSlots.default({mutate:this.mutate,loading:this.loading,error:this.error,gqlError:this.error&&this.error.gqlError});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},j=["$subscribe"];function D(t,e){return void 0!==t&&Object.prototype.hasOwnProperty.call(t,e)}function x(){var t=this,e=this.$options.apollo;if(e){var i=function(i){"$"!==i.charAt(0)&&(e[i].manual||D(t.$options.props,i)||D(t.$options.computed,i)||D(t.$options.methods,i)||Object.defineProperty(t,i,{get:function(){return t.$data.$apolloData.data[i]},enumerable:!0,configurable:!0}))};for(var o in e)i(o)}}function L(){var t=this,e=this.$apolloProvider;if(!this._apolloLaunched&&e){this._apolloLaunched=!0;var i=this.$options.apollo;if(i){for(var o in i.$init||(i.$init=!0,e.defaultOptions&&(i=this.$options.apollo=Object.assign({},e.defaultOptions,i))),E(this.$apollo,"skipAll",i.$skipAll,i.$deep),E(this.$apollo,"skipAllQueries",i.$skipAllQueries,i.$deep),E(this.$apollo,"skipAllSubscriptions",i.$skipAllSubscriptions,i.$deep),E(this.$apollo,"client",i.$client,i.$deep),E(this.$apollo,"loadingKey",i.$loadingKey,i.$deep),E(this.$apollo,"error",i.$error,i.$deep),E(this.$apollo,"watchLoading",i.$watchLoading,i.$deep),Object.defineProperty(this,"$apolloData",{get:function(){return t.$data.$apolloData},enumerable:!0,configurable:!0}),i)if("$"!==o.charAt(0)){var r=i[o];this.$apollo.addSmartQuery(o,r)}if(i.subscribe&&c.Vue.util.warn("vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead."),i.$subscribe)for(var n in i.$subscribe)this.$apollo.addSmartSubscription(n,i.$subscribe[n])}}}function E(t,e,i,o){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,o):t[e]=i)}function C(t,e){if(!C.installed){C.installed=!0,c.Vue=t;var i=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,o){if(!t)return e;if(!e)return t;for(var r=Object.assign({},y(t,j),t.data),n=Object.assign({},y(e,j),e.data),s={},a=0;at?u():!0!==e&&(r=setTimeout(o?function(){r=void 0}:u,void 0===o?t-a:t))}}var i="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},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var i=0;i3&&void 0!==arguments[3])||arguments[3];o(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=i,this.initialOptions=r,this.options=Object.assign({},r),this._skip=!1,this._watchers=[],this._destroyed=!1,this.vm.$isServer&&(this.options.fetchPolicy="cache-first"),n&&this.autostart()}return r(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._skipWatcher=this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0,deep:this.options.deep}):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.initialOptions.query){var e=this.initialOptions.query.bind(this.vm);this.options.query=e(),this._watchers.push(this.vm.$watch(e,function(e){t.options.query=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.initialOptions.document){var i=this.initialOptions.document.bind(this.vm);this.options.document=i(),this._watchers.push(this.vm.$watch(i,function(e){t.options.document=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.initialOptions.context){var o=this.initialOptions.context.bind(this.vm);this.options.context=o(),this._watchers.push(this.vm.$watch(o,function(e){t.options.context=e,t.refresh()},{deep:this.options.deep}))}if("function"==typeof this.options.variables){var r=this.executeApollo.bind(this);r=this.options.throttle?f(r,this.options.throttle):r,r=this.options.debounce?d(r,this.options.debounce):r,this._watchers.push(this.vm.$watch(function(){return t.options.variables.call(t.vm)},r,{immediate:!0,deep:this.options.deep}))}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){var t=!0,e=!1,i=void 0;try{for(var o,r=this._watchers[Symbol.iterator]();!(t=(o=r.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,i=t}finally{try{!t&&r.return&&r.return()}finally{if(e)throw i}}this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=y(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(t){var e=t.error;e&&b(e)}},{key:"callHandlers",value:function(t){for(var e=!1,i=arguments.length,o=Array(i>1?i-1:0),r=1;r3&&void 0!==arguments[3])||arguments[3];(o(this,e),r.query)||(r={query:r});t.$data.$apolloData&&!t.$data.$apolloData.queries[i]&&t.$set(t.$data.$apolloData.queries,i,{loading:!1});var s=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i,r,n));return s.type="query",s.vueApolloSpecialKeys=m,s._loading=!1,r.manual||(s.hasDataField=s.vm.$data.hasOwnProperty(i),s.hasDataField?Object.defineProperty(s.vm.$data.$apolloData.data,i,{get:function(){return s.vm.$data[i]},enumerable:!0,configurable:!0}):Object.defineProperty(s.vm.$data,i,{get:function(){return s.vm.$data.$apolloData.data[i]},enumerable:!0,configurable:!0})),s}return a(e,g),r(e,[{key:"stop",value:function(){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){if(this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t))),this.startQuerySubscription(),"no-cache"!==this.options.fetchPolicy){var i=this.maySetLoading();i.loading||this.nextResult(i)}s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"startQuerySubscription",value:function(){this.sub&&!this.sub.closed||(this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)}))}},{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){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"nextResult",this).call(this,t);var i=t.data;t.loading||this.loadingDone();var o="function"==typeof this.options.result;void 0===i||(this.options.manual?o||console.error(this.key+" query must have a 'result' hook in manual mode"):"function"==typeof this.options.update?this.setData(this.options.update.call(this.vm,i)):void 0===i[this.key]&&Object.keys(i).length?console.error("Missing "+this.key+" attribute on result",i):this.setData(i[this.key])),o&&this.options.result.call(this.vm,t)}},{key:"setData",value:function(t){this.vm.$set(this.hasDataField?this.vm.$data:this.vm.$data.$apolloData.data,this.key,t)}},{key:"catchError",value:function(t){s(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone(),this.nextResult(this.observer.currentResult()),this.resubscribeToQuery()}},{key:"resubscribeToQuery",value:function(){var t=this.observer.getLastError(),e=this.observer.getLastResult();this.observer.resetLastResults(),this.startQuerySubscription(),Object.assign(this.observer,{lastError:t,lastResult:e})}},{key:"watchLoading",value:function(){for(var t=arguments.length,e=Array(t),i=0;i0&&void 0!==arguments[0]?arguments[0]:null;if(!t||!t.client){if("object"===i(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 o=this.provider.clients[t.client];if(!o)throw new Error("[vue-apollo] Missing client '"+t.client+"' in 'apolloProvider'");return o}},{key:"watchQuery",value:function(t){var e=this,i=this.getClient(t).watchQuery(t),o=i.subscribe.bind(i);return i.subscribe=function(t){var i=o(t);return e._apolloSubscriptions.push(i),i},i}},{key:"mutate",value:function(t){return this.getClient(t).mutate(t)}},{key:"subscribe",value:function(t){var e=this;if(!this.vm.$isServer){var i=this.getClient(t).subscribe(t),o=i.subscribe.bind(i);return i.subscribe=function(t){var i=o(t);return e._apolloSubscriptions.push(i),i},i}}},{key:"addSmartQuery",value:function(t,e){var i=this,o=v(e,this.vm),r=this.vm.$options.apollo,s=this.provider.defaultOptions,a=void 0;if(r&&r.$query&&(a=r.$query),r&&r.$query||!s||!s.$query||(a=s.$query),a)for(var l in a)void 0===o[l]&&(o[l]=a[l]);var u=this.queries[t]=new $(this.vm,t,o,!1);if(u.autostart(),!this.vm.$isServer){var h=o.subscribeToMore;h&&(Array.isArray(h)?h.forEach(function(e,o){i.addSmartSubscription(""+t+o,n({},e,{linkedQuery:u}))}):this.addSmartSubscription(t,n({},h,{linkedQuery:u})))}return u}},{key:"addSmartSubscription",value:function(t,e){if(!this.vm.$isServer){e=v(e,this.vm);var i=this.subscriptions[t]=new k(this.vm,t,e,!1);return i.autostart(),i}}},{key:"defineReactiveSetter",value:function(t,e,i){var o=this;this._watchers.push(this.vm.$watch(e,function(e){o[t]=e},{immediate:!0,deep:i}))}},{key:"destroy",value:function(){var t=!0,e=!1,i=void 0;try{for(var o,r=this._watchers[Symbol.iterator]();!(t=(o=r.next()).done);t=!0){(0,o.value)()}}catch(t){e=!0,i=t}finally{try{!t&&r.return&&r.return()}finally{if(e)throw i}}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 0!==this.vm.$data.$apolloData.loading}},{key:"data",get:function(){return this.vm.$data.$apolloData.data}},{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}(),_=function(){function t(e){if(o(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 r(t,[{key:"provide",value:function(){return function(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,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 i;i=t;var o=(t=c.Vue.util.mergeOptions({},i)).apollo;if(o){var r=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||r)}}}},{key:"prefetchComponents",value:function(t){var e=!0,i=!1,o=void 0;try{for(var r,n=t[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var s=r.value;this.prefetchComponent(s)}}catch(t){i=!0,o=t}finally{try{!e&&n.return&&n.return()}finally{if(i)throw o}}}},{key:"prefetchAll",value:function(t,e,i){var o=this;i||!e||Array.isArray(e)||(i=e,e=void 0);var r=Object.assign({},{includeGlobal:!0},i);return e&&this.prefetchComponents(e),r.includeGlobal&&this.prefetchComponents(w.filter(function(e){e.component;var i=e.contextCallback,o=!0;return"function"==typeof i&&(o=!!i(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,o){var r=void 0;if(o){if("string"==typeof o&&!(o=this.clients[o]))throw new Error("[vue-apollo] Missing client '"+o+"' in 'apolloProvider'")}else o=this.defaultClient;if(t.query){var n=t.prefetch,s=void 0===n?"undefined":i(n);if("undefined"!==s){var a=void 0;if(!(a="function"===s?n(e):n))return Promise.resolve();if("boolean"===s){var l=t.variables;r=void 0!==l?"function"==typeof l?l.call(e):l:void 0}else r=a}}else t={query:t};return"function"==typeof t.query&&(t.query=t.query(e)),new Promise(function(e,i){var n=y(t,[].concat(h(m),["fetchPolicy"]));n.variables=r,n.fetchPolicy="network-only",o.query(n).then(e,i)})}},{key:"getStates",value:function(t){var e=Object.assign({},{exportNamespace:""},t),i={};for(var o in this.clients){var r=this.clients[o].cache.extract();i[""+e.exportNamespace+o]=r}return i}},{key:"exportStates",value:function(t){var e=Object.assign({},{globalName:"__APOLLO_STATE__",attachTo:"window"},t),i=this.getStates(e);return e.attachTo+"."+e.globalName+" = "+JSON.stringify(i)+";"}}]),t}(),w=[];function S(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return w.push({component:t,contextCallback:e}),t}"undefined"!=typeof window?window.vueApolloWillPrefetch=S:"undefined"!=typeof global&&(global.vueApolloWillPrefetch=S);var A={name:"ApolloQuery",provide:function(){return{getDollarApollo:this.getDollarApollo,getApolloQuery:this.getApolloQuery}},props:{query:{type: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},skip:{type:Boolean,default:!1},clientId:{type:String,default:void 0},deep:{type:Boolean,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},deep:this.deep,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 occured ("+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),this.result={data:function(t){return Object.keys(t).length>0}(s)?s:void 0,loading:o,error:n,networkStatus:r},this.times=++this.$_times,this.$emit("result",this.result)},error:function(t){this.result.loading=!1,this.result.error=t,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,times:this.times,query:this.$apollo.queries.query,isLoading:this.$apolloData.loading,gqlError:this.result&&this.result.error&&this.result.error.gqlError});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},q=0,P={name:"ApolloSubscribeToMore",inject:["getDollarApollo","getApolloQuery"],props:{document:{type:Object,required:!0},variables:{type:Object,default:void 0},updateQuery:{type:Function,default:void 0}},watch:{document:"refresh",variables:"refresh"},created:function(){this.$_key="sub_component_"+q++},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}},Q={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=this;this.loading=!0,this.error=null,this.$apollo.mutate(n({mutation:this.mutation,variables:this.variables,optimisticResponse:this.optimisticResponse,update:this.update,refetchQueries:this.refetchQueries},t)).then(function(t){e.$emit("done",t),e.loading=!1}).catch(function(t){b(t),e.error=t,e.$emit("error",t),e.loading=!1})}},render:function(t){var e=this.$scopedSlots.default({mutate:this.mutate,loading:this.loading,error:this.error,gqlError:this.error&&this.error.gqlError});return e=Array.isArray(e)?e.concat(this.$slots.default):[e].concat(this.$slots.default),t(this.tag,e)}},j=["$subscribe"];function D(t,e){return void 0!==t&&Object.prototype.hasOwnProperty.call(t,e)}function x(){var t=this,e=this.$options.apollo;if(e){var i=function(i){"$"!==i.charAt(0)&&(e[i].manual||D(t.$options.props,i)||D(t.$options.computed,i)||D(t.$options.methods,i)||Object.defineProperty(t,i,{get:function(){return t.$data.$apolloData.data[i]},enumerable:!0,configurable:!0}))};for(var o in e)i(o)}}function L(){var t=this,e=this.$apolloProvider;if(!this._apolloLaunched&&e){this._apolloLaunched=!0;var i=this.$options.apollo;if(i){for(var o in i.$init||(i.$init=!0,e.defaultOptions&&(i=this.$options.apollo=Object.assign({},e.defaultOptions,i))),E(this.$apollo,"skipAll",i.$skipAll,i.$deep),E(this.$apollo,"skipAllQueries",i.$skipAllQueries,i.$deep),E(this.$apollo,"skipAllSubscriptions",i.$skipAllSubscriptions,i.$deep),E(this.$apollo,"client",i.$client,i.$deep),E(this.$apollo,"loadingKey",i.$loadingKey,i.$deep),E(this.$apollo,"error",i.$error,i.$deep),E(this.$apollo,"watchLoading",i.$watchLoading,i.$deep),Object.defineProperty(this,"$apolloData",{get:function(){return t.$data.$apolloData},enumerable:!0,configurable:!0}),i)if("$"!==o.charAt(0)){var r=i[o];this.$apollo.addSmartQuery(o,r)}if(i.subscribe&&c.Vue.util.warn("vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead."),i.$subscribe)for(var n in i.$subscribe)this.$apollo.addSmartSubscription(n,i.$subscribe[n])}}}function E(t,e,i,o){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,o):t[e]=i)}function C(t,e){if(!C.installed){C.installed=!0,c.Vue=t;var i=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,o){if(!t)return e;if(!e)return t;for(var r=Object.assign({},y(t,j),t.data),n=Object.assign({},y(e,j),e.data),s={},a=0;a