UNPKG

vue-apollo

Version:

Use Apollo and GraphQL with Vue.js

2 lines (1 loc) 29.5 kB
var VueApollo=function(t,r){"use strict";function i(t){return(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})(t)}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function l(t,e,i){return e&&o(t.prototype,e),i&&o(t,i),t}function u(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function n(e,t){var i,r=Object.keys(e);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(e),t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,i)),r}function c(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?n(Object(i),!0).forEach(function(t){u(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(i){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=h(i);return t=r?(t=h(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments),e=this,!(t=t)||"object"!=typeof t&&"function"!=typeof t?p(e):t}}function d(t,e,i){return(d="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,i){t=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=h(t)););return t}(t,e);if(t){e=Object.getOwnPropertyDescriptor(t,e);return e.get?e.get.call(i):e.value}})(t,e,i||t)}function v(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var i=[],r=!0,o=!1,n=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(i.push(s.value),!e||i.length!==e);r=!0);}catch(t){o=!0,n=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw n}}return i}(t,e)||b(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t){return function(t){if(Array.isArray(t))return g(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||b(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t,e){if(t){if("string"==typeof t)return g(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(i="Object"===i&&t.constructor?t.constructor.name:i)||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?g(t,e):void 0}}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,r=new Array(e);i<e;i++)r[i]=t[i];return r}r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;function m(t,e){return t(e={exports:{}},e.exports),e.exports}var $,k=m(function(t,e){function r(s,a,l,u){var c,h=!1,p=0;function f(){c&&clearTimeout(c)}function t(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];var r=this,o=Date.now()-p;function n(){p=Date.now(),l.apply(r,e)}h||(u&&!c&&n(),f(),void 0===u&&s<o?n():!0!==a&&(c=setTimeout(u?function(){c=void 0}:n,void 0===u?s-o:s)))}return"boolean"!=typeof a&&(u=l,l=a,a=void 0),t.cancel=function(){f(),h=!0},t}(e=e).debounce=function(t,e,i){return void 0===i?r(t,e,!1):r(t,i,!1!==e)},e.throttle=r,Object.defineProperty(e,"__esModule",{value:!0})});($=k)&&$.__esModule&&Object.prototype.hasOwnProperty.call($,"default")&&$.default;var O=m(function(t,e){var i=e.Globals={};function r(i){return function(t,e){return i(e,t)}}e.throttle=r(k.throttle),e.debounce=r(k.debounce),e.getMergedDefinition=function(t){return i.Vue.util.mergeOptions({},t)},e.reapply=function(t,e){for(;"function"==typeof t;)t=t.call(e);return t},e.omit=function(t,e){return Object.entries(t).filter(function(t){t=v(t,1)[0];return!e.includes(t)}).reduce(function(t,e){var i=v(e,2),e=i[0],i=i[1];return t[e]=i,t},{})},e.addGqlError=function(t){t.graphQLErrors&&t.graphQLErrors.length&&(t.gqlError=t.graphQLErrors[0])},e.noop=function(){}}),w=O.Globals,S=O.throttle,A=O.debounce,_=(O.getMergedDefinition,O.reapply),j=O.omit,R=O.addGqlError,P=(O.noop,{query:"_skipAllQueries",subscription:"_skipAllSubscriptions"}),q=function(){function r(t,e,i){a(this,r),u(this,"type",null),u(this,"vueApolloSpecialKeys",[]),this.vm=t,this.key=e,this.initialOptions=i,this.options=Object.assign({},i),this._skip=!1,this._pollInterval=null,this._watchers=[],this._destroyed=!1,this.lastApolloOptions=null}return l(r,[{key:"autostart",value:function(){var t=this;"function"==typeof this.options.skip?this._skipWatcher=this.vm.$watch(function(){return t.options.skip.call(t.vm,t.vm,t.key)},this.skipChanged.bind(this),{immediate:!0,deep:this.options.deep}):this.options.skip||this.allSkip?this._skip=!0:this.start(),"function"==typeof this.options.pollInterval&&(this._pollWatcher=this.vm.$watch(this.options.pollInterval.bind(this.vm),this.pollIntervalChanged.bind(this),{immediate:!0}))}},{key:"pollIntervalChanged",value:function(t,e){t!==e&&(null==(this.pollInterval=t)?this.stopPolling():this.startPolling(t))}},{key:"skipChanged",value:function(t,e){t!==e&&(this.skip=t)}},{key:"pollInterval",get:function(){return this._pollInterval},set:function(t){this._pollInterval=t}},{key:"skip",get:function(){return this._skip},set:function(t){t||this.allSkip?this.stop():this.start(),this._skip=t}},{key:"allSkip",get:function(){return this.vm.$apollo[P[this.type]]}},{key:"refresh",value:function(){this._skip||(this.stop(),this.start())}},{key:"start",value:function(){var r=this;this.starting=!0;for(var t,e=0,i=["query","document","context"];e<i.length;e++)!function(t,e){var i=e[t];"function"==typeof r.initialOptions[i]&&(e=r.initialOptions[i].bind(r.vm),r.options[i]=e(),t=function(t){r.options[i]=t,r.refresh()},r.vm.$isServer||(t=r.options.throttle?S(t,r.options.throttle):t,t=r.options.debounce?A(t,r.options.debounce):t),r._watchers.push(r.vm.$watch(e,t,{deep:r.options.deep})))}(e,i);"function"==typeof this.options.variables?(t=this.executeApollo.bind(this),this.vm.$isServer||(t=this.options.throttle?S(t,this.options.throttle):t,t=this.options.debounce?A(t,this.options.debounce):t),this._watchers.push(this.vm.$watch(function(){return"function"==typeof r.options.variables?r.options.variables.call(r.vm):r.options.variables},t,{immediate:!0,deep:this.options.deep}))):this.executeApollo(this.options.variables)}},{key:"stop",value:function(){for(var t=0,e=this._watchers;t<e.length;t++)(0,e[t])();this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=j(this.options,this.vueApolloSpecialKeys);return e.variables=t,this.lastApolloOptions=e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(t){t=t.error;t&&R(t)}},{key:"callHandlers",value:function(t){for(var e=!1,i=arguments.length,r=new Array(1<i?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];for(var n=0;n<t.length;n++){var s=t[n];if(s){e=!0;s=s.apply(this.vm,r);if(void 0!==s&&!s)break}}return e}},{key:"errorHandler",value:function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return this.callHandlers.apply(this,[[this.options.error,this.vm.$apollo.error,this.vm.$apollo.provider.errorHandler]].concat(e))}},{key:"catchError",value:function(t){var e;if(R(t),!this.errorHandler(t,this.vm,this.key,this.type,this.lastApolloOptions))if(t.graphQLErrors&&0!==t.graphQLErrors.length){console.error("GraphQL execution errors for ".concat(this.type," '").concat(this.key,"'"));for(var i=0,r=t.graphQLErrors;i<r.length;i++){var o=r[i];console.error(o)}}else t.networkError?console.error("Error sending the ".concat(this.type," '").concat(this.key,"'"),t.networkError):(console.error("[vue-apollo] An error has occurred for ".concat(this.type," '").concat(this.key,"'")),Array.isArray(t)?(e=console).error.apply(e,y(t)):console.error(t))}},{key:"destroy",value:function(){this._destroyed||(this._destroyed=!0,this.stop(),this._skipWatcher&&this._skipWatcher())}}]),r}(),D=["variables","watch","update","result","error","loadingKey","watchLoading","skip","throttle","debounce","subscribeToMore","prefetch","manual"],Q=function(){e(s,q);var n=f(s);function s(t,e,i){var r,o=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];return a(this,s),t.$data.$apolloData&&!t.$data.$apolloData.queries[e]&&t.$set(t.$data.$apolloData.queries,e,{loading:!1}),u(p(r=n.call(this,t,e,i)),"type","query"),u(p(r),"vueApolloSpecialKeys",D),u(p(r),"_loading",!1),u(p(r),"_linkedSubscriptions",[]),t.$isServer&&(r.firstRun=new Promise(function(t,e){r._firstRunResolve=t,r._firstRunReject=e})),r.vm.$isServer&&(r.options.fetchPolicy="network-only"),i.manual||(r.hasDataField=Object.prototype.hasOwnProperty.call(r.vm.$data,e),r.hasDataField?Object.defineProperty(r.vm.$data.$apolloData.data,e,{get:function(){return r.vm.$data[e]},enumerable:!0,configurable:!0}):Object.defineProperty(r.vm.$data,e,{get:function(){return r.vm.$data.$apolloData.data[e]},enumerable:!0,configurable:!0})),o&&r.autostart(),r}return l(s,[{key:"client",get:function(){return this.vm.$apollo.getClient(this.options)}},{key:"loading",get:function(){return this.vm.$data.$apolloData&&this.vm.$data.$apolloData.queries[this.key]?this.vm.$data.$apolloData.queries[this.key].loading:this._loading},set:function(t){this._loading!==t&&(this._loading=t,this.vm.$data.$apolloData&&this.vm.$data.$apolloData.queries[this.key]&&(this.vm.$data.$apolloData.queries[this.key].loading=t,this.vm.$data.$apolloData.loading+=t?1:-1))}},{key:"stop",value:function(){d(h(s.prototype),"stop",this).call(this),this.loadingDone(),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"generateApolloOptions",value:function(t){t=d(h(s.prototype),"generateApolloOptions",this).call(this,t);return this.vm.$isServer&&delete t.pollInterval,t}},{key:"executeApollo",value:function(t){var e=JSON.stringify(t);if(this.sub){if(e===this.previousVariablesJson)return;this.sub.unsubscribe();for(var i=0,r=this._linkedSubscriptions;i<r.length;i++)r[i].stop()}this.previousVariablesJson=e,this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t)),this.startQuerySubscription(),"no-cache"===this.options.fetchPolicy&&!this.options.notifyOnNetworkStatusChange||(e=this.retrieveCurrentResult(),(this.options.notifyOnNetworkStatusChange||this.observer.getCurrentResult&&!e.loading)&&this.nextResult(e)),d(h(s.prototype),"executeApollo",this).call(this,t);for(var o=0,n=this._linkedSubscriptions;o<n.length;o++)n[o].start()}},{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:"retrieveCurrentResult",value:function(){var t=0<arguments.length&&void 0!==arguments[0]&&arguments[0],e=this.observer.getCurrentResult?this.observer.getCurrentResult():this.observer.currentResult();return(t||e.loading)&&(this.loading||this.applyLoadingModifier(1),this.loading=!0),e}},{key:"nextResult",value:function(t){d(h(s.prototype),"nextResult",this).call(this,t);var e=t.data,i=t.loading,r=t.error,o=t.errors,n=o&&o.length;(r||n)&&this.firstRunReject(r),i||this.loadingDone(),n&&(i=new Error("GraphQL error: ".concat(o.map(function(t){return t.message}).join(" | "))),Object.assign(i,{graphQLErrors:o,networkError:null}),d(h(s.prototype),"catchError",this).call(this,i)),"none"===this.observer.options.errorPolicy&&(r||n)||(n="function"==typeof this.options.result,null==e||(this.options.manual?n||console.error("".concat(this.key," query must have a 'result' hook in manual mode")):"function"==typeof this.options.update?this.setData(this.options.update.call(this.vm,e)):void 0===e[this.key]&&Object.keys(e).length?console.error("Missing ".concat(this.key," attribute on result"),e):this.setData(e[this.key])),n&&this.options.result.call(this.vm,t,this.key))}},{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){d(h(s.prototype),"catchError",this).call(this,t),this.firstRunReject(t),this.loadingDone(t),this.nextResult(this.observer.getCurrentResult?this.observer.getCurrentResult():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:"loadingKey",get:function(){return this.options.loadingKey||this.vm.$apollo.loadingKey}},{key:"watchLoading",value:function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return this.callHandlers.apply(this,[[this.options.watchLoading,this.vm.$apollo.watchLoading,this.vm.$apollo.provider.watchLoading]].concat(e,[this]))}},{key:"applyLoadingModifier",value:function(t){var e=this.loadingKey;e&&"number"==typeof this.vm[e]&&(this.vm[e]+=t),this.watchLoading(1===t,t)}},{key:"loadingDone",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;this.loading&&this.applyLoadingModifier(-1),this.loading=!1,t||this.firstRunResolve()}},{key:"fetchMore",value:function(){var t,e=this;if(this.observer)return this.retrieveCurrentResult(!0),(t=this.observer).fetchMore.apply(t,arguments).then(function(t){return t.loading||e.loadingDone(),t})}},{key:"subscribeToMore",value:function(){var t;if(this.observer)return{unsubscribe:(t=this.observer).subscribeToMore.apply(t,arguments)}}},{key:"refetch",value:function(t){var e=this;if(t&&(this.options.variables=t),this.observer){t=this.observer.refetch(t).then(function(t){return t.loading||e.loadingDone(),t});return this.retrieveCurrentResult(),t}}},{key:"setVariables",value:function(t,e){if(this.options.variables=t,this.observer){e=this.observer.setVariables(t,e);return this.retrieveCurrentResult(),e}}},{key:"setOptions",value:function(t){if(Object.assign(this.options,t),this.observer){t=this.observer.setOptions(t);return this.retrieveCurrentResult(),t}}},{key:"startPolling",value:function(){var t;if(this.observer)return(t=this.observer).startPolling.apply(t,arguments)}},{key:"stopPolling",value:function(){var t;if(this.observer)return(t=this.observer).stopPolling.apply(t,arguments)}},{key:"firstRunResolve",value:function(){this._firstRunResolve&&(this._firstRunResolve(),this._firstRunResolve=null)}},{key:"firstRunReject",value:function(t){this._firstRunReject&&(this._firstRunReject(t),this._firstRunReject=null)}},{key:"destroy",value:function(){d(h(s.prototype),"destroy",this).call(this),this.loading&&this.watchLoading(!1,-1),this.loading=!1}}]),s}(),E=function(){e(n,q);var o=f(n);function n(t,e,i){var r=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];return a(this,n),u(p(i=o.call(this,t,e,i)),"type","subscription"),u(p(i),"vueApolloSpecialKeys",["variables","result","error","throttle","debounce","linkedQuery"]),i.attempts=0,r&&i.autostart(),i}return l(n,[{key:"generateApolloOptions",value:function(t){t=d(h(n.prototype),"generateApolloOptions",this).call(this,t);return t.onError=this.catchError.bind(this),t}},{key:"executeApollo",value:function(t){if(!this._destroyed){var e=JSON.stringify(t);if(this.sub){if(e===this.previousVariablesJson)return;this.sub.unsubscribe()}this.previousVariablesJson=e;var i,r,e=this.generateApolloOptions(t);"function"==typeof e.updateQuery&&(e.updateQuery=e.updateQuery.bind(this.vm)),this.options.linkedQuery?("function"==typeof this.options.result&&(i=this.options.result.bind(this.vm),r=e.updateQuery&&e.updateQuery.bind(this.vm),e.updateQuery=function(){return i.apply(void 0,arguments),r&&r.apply(void 0,arguments)}),this.sub=this.options.linkedQuery.subscribeToMore(e)):(this.observer=this.vm.$apollo.subscribe(e),this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)})),d(h(n.prototype),"executeApollo",this).call(this,t)}}},{key:"nextResult",value:function(t){d(h(n.prototype),"nextResult",this).call(this,t),this.attempts=0,"function"==typeof this.options.result&&this.options.result.call(this.vm,t,this.key)}},{key:"catchError",value:function(t){d(h(n.prototype),"catchError",this).call(this,t),this.skip||5<=this.attempts||(this.stop(),this.retryTimeout=setTimeout(this.start.bind(this),500*Math.pow(2,this.attempts)),this.attempts++)}},{key:"stop",value:function(){d(h(n.prototype),"stop",this).call(this),clearTimeout(this.retryTimeout)}}]),n}(),C=function(){function e(t){a(this,e),this._apolloSubscriptions=[],this._watchers=[],this.vm=t,this.queries={},this.subscriptions={},this.client=void 0,this.loadingKey=void 0,this.error=void 0}return l(e,[{key:"provider",get:function(){return this.vm.$apolloProvider}},{key:"getClient",value:function(){var t=0<arguments.length&&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 '".concat(this.client,"' in 'apolloProvider'"));return e}throw new Error("[vue-apollo] Missing 'clients' options in 'apolloProvider'")}return this.provider.defaultClient}e=this.provider.clients[t.client];if(!e)throw new Error("[vue-apollo] Missing client '".concat(t.client,"' in 'apolloProvider'"));return e}},{key:"query",value:function(t){return this.getClient(t).query(t)}},{key:"watchQuery",value:function(t){var e=this,t=this.getClient(t).watchQuery(t),i=t.subscribe.bind(t);return t.subscribe=function(t){t=i(t);return e._apolloSubscriptions.push(t),t},t}},{key:"mutate",value:function(t){return this.getClient(t).mutate(t)}},{key:"subscribe",value:function(t){var e=this;if(!this.vm.$isServer){var t=this.getClient(t).subscribe(t),i=t.subscribe.bind(t);return t.subscribe=function(t){t=i(t);return e._apolloSubscriptions.push(t),t},t}}},{key:"loading",get:function(){return 0!==this.vm.$data.$apolloData.loading}},{key:"data",get:function(){return this.vm.$data.$apolloData.data}},{key:"addSmartQuery",value:function(i,t){var r=this,e=_(t,this.vm);e.query||(e={query:e});var o,n=this.vm.$options.apollo,t=this.provider.defaultOptions;if(t&&t.$query&&(o=t.$query),o=n&&n.$query?c(c({},o||{}),n.$query):o)for(var s in o)void 0===e[s]&&(e[s]=o[s]);var a=this.queries[i]=new Q(this.vm,i,e,!1);return this.vm.$isServer&&!1===e.prefetch||a.autostart(),this.vm.$isServer||(n=e.subscribeToMore)&&(Array.isArray(n)?n.forEach(function(t,e){r.addSmartSubscription("".concat(i).concat(e),c(c({},t),{},{linkedQuery:a}))}):this.addSmartSubscription(i,c(c({},n),{},{linkedQuery:a}))),a}},{key:"addSmartSubscription",value:function(t,e){if(!this.vm.$isServer){e=_(e,this.vm);t=this.subscriptions[t]=new E(this.vm,t,e,!1);return t.autostart(),e.linkedQuery&&e.linkedQuery._linkedSubscriptions.push(t),t}}},{key:"defineReactiveSetter",value:function(e,t,i){var r=this;this._watchers.push(this.vm.$watch(t,function(t){r[e]=t},{immediate:!0,deep:i}))}},{key:"skipAllQueries",set:function(t){for(var e in this._skipAllQueries=t,this.queries)this.queries[e].skip=t}},{key:"skipAllSubscriptions",set:function(t){for(var e in this._skipAllSubscriptions=t,this.subscriptions)this.subscriptions[e].skip=t}},{key:"skipAll",set:function(t){this.skipAllQueries=t,this.skipAllSubscriptions=t}},{key:"destroy",value:function(){for(var t,e,i=0,r=this._watchers;i<r.length;i++)(0,r[i])();for(t in this.queries)this.queries[t].destroy();for(e in this.subscriptions)this.subscriptions[e].destroy();this._apolloSubscriptions.forEach(function(t){t.unsubscribe()})}}]),e}(),x=function(){function e(t){if(a(this,e),!t)throw new Error("Options argument required");this.clients=t.clients||{},t.defaultClient&&(this.clients.defaultClient=this.defaultClient=t.defaultClient),this.defaultOptions=t.defaultOptions,this.watchLoading=t.watchLoading,this.errorHandler=t.errorHandler,this.prefetch=t.prefetch}return l(e,[{key:"provide",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"$apolloProvider";return console.warn("<ApolloProvider>.provide() is deprecated. Use the 'apolloProvider' option instead with the provider object directly."),u({},t,this)}}]),e}();var L={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(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.errors,i=t.loading,r=t.networkStatus,o=t.error;t=Object.assign({},t),e&&e.length&&((o=new Error("Apollo errors occurred (".concat(e.length,")"))).graphQLErrors=e);e={};i?Object.assign(e,this.$_previousData,t.data):o?Object.assign(e,this.$apollo.queries.query.observer.getLastResult()||{},t.data):(e=t.data,this.$_previousData=t.data);t=(t=e)&&0<Object.keys(t).length;this.result={data:t?this.update(e):void 0,fullData:t?e:void 0,loading:i,error:o,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}),e=(Array.isArray(e)?e:[e]).concat(this.$slots.default);return this.tag?t(this.tag,e):e[0]}},M=0,I={name:"ApolloSubscribeToMore",inject:["getDollarApollo","getApolloQuery"],props:{document:{type:[Function,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_".concat(M++)},mounted:function(){this.refresh()},beforeDestroy:function(){this.destroy()},methods:{destroy:function(){this.$_sub&&this.$_sub.destroy()},refresh:function(){this.destroy();var t=this.document;"function"==typeof t&&(t=t(r)),this.$_sub=this.getDollarApollo().addSmartSubscription(this.$_key,{document:t,variables:this.variables,updateQuery:this.updateQuery,linkedQuery:this.getApolloQuery()})}},render:function(t){return null}},T={props:{mutation:{type:[Function,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},clientId:{type:String,default:void 0},tag:{type:String,default:"div"},context:{type:Object,default:void 0}},data:function(){return{loading:!1,error:null}},watch:{loading:function(t){this.$emit("loading",t)}},methods:{mutate:function(t){var e=this;this.loading=!0,this.error=null;var i=this.mutation;return"function"==typeof i&&(i=i(r)),this.$apollo.mutate(c({mutation:i,client:this.clientId,variables:this.variables,optimisticResponse:this.optimisticResponse,update:this.update,refetchQueries:this.refetchQueries,context:this.context},t)).then(function(t){return e.$emit("done",t),e.loading=!1,t}).catch(function(t){R(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}),e=(Array.isArray(e)?e:[e]).concat(this.$slots.default);return this.tag?t(this.tag,e):e[0]}};function K(t,e){return void 0!==t&&Object.prototype.hasOwnProperty.call(t,e)}function N(){var t=this.$options,e=t.apolloProvider;e?this.$apolloProvider="function"==typeof e?e():e:t.parent&&t.parent.$apolloProvider&&(this.$apolloProvider=t.parent.$apolloProvider)}function V(){var i=this;this.$_apolloInitData={};var t=this.$options.apollo;if(t)for(var e in t)!function(e){"$"!==e.charAt(0)&&(t[e].manual||K(i.$options.props,e)||K(i.$options.computed,e)||K(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}))}(e)}function F(){var t=this,e=this.$apolloProvider;if(!this._apolloLaunched&&e){this._apolloLaunched=!0;var i,r,o=this.$options.apollo;if(o){for(var n in this.$_apolloPromises=[],o.$init||(o.$init=!0,e.defaultOptions&&(o=this.$options.apollo=Object.assign({},e.defaultOptions,o))),H(this.$apollo,"skipAll",o.$skipAll,o.$deep),H(this.$apollo,"skipAllQueries",o.$skipAllQueries,o.$deep),H(this.$apollo,"skipAllSubscriptions",o.$skipAllSubscriptions,o.$deep),H(this.$apollo,"client",o.$client,o.$deep),H(this.$apollo,"loadingKey",o.$loadingKey,o.$deep),H(this.$apollo,"error",o.$error,o.$deep),H(this.$apollo,"watchLoading",o.$watchLoading,o.$deep),Object.defineProperty(this,"$apolloData",{get:function(){return t.$data.$apolloData},enumerable:!0,configurable:!0}),o)"$"!==n.charAt(0)&&(i=o[n],r=this.$apollo.addSmartQuery(n,i),this.$isServer&&(i=_(i,this),!1===e.prefetch||!1===i.prefetch||!1===o.$prefetch||r.skip||this.$_apolloPromises.push(r.firstRun)));if(o.subscribe&&w.Vue.util.warn("vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead."),o.$subscribe)for(var s in o.$subscribe)this.$apollo.addSmartSubscription(s,o.$subscribe[s])}}}function H(t,e,i,r){void 0!==i&&("function"==typeof i?t.defineReactiveSetter(e,i,r):t[e]=i)}function G(){this.$_apollo&&this.$_apollo.destroy()}var J=["$subscribe"];function B(t,e){var i,l,r;B.installed||(B.installed=!0,i=(w.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({},j(t,J),t.data),o=Object.assign({},j(e,J),e.data),n={},s=0;s<J.length;s++){var a=J[s];n[a]=l(t[a],e[a])}return Object.assign(n,l(r,o))},Object.prototype.hasOwnProperty.call(t,"$apollo")||Object.defineProperty(t.prototype,"$apollo",{get:function(){return this.$_apollo||(this.$_apollo=new C(this)),this.$_apollo}}),r=i,t.mixin(c(c(c({},"1"===r?{init:N}:{}),"2"===r?{data:function(){return{$apolloData:{queries:{},loading:0,data:this.$_apolloInitData}}},beforeCreate:function(){N.call(this),V.call(this)},serverPrefetch:function(){var e=this;if(this.$_apolloPromises)return Promise.all(this.$_apolloPromises).then(function(){G.call(e)}).catch(function(t){return G.call(e),Promise.reject(t)})}}:{}),{},{created:F,destroyed:G})),"2"===i&&(t.component("ApolloQuery",L),t.component("ApolloQuery",L),t.component("ApolloSubscribeToMore",I),t.component("ApolloSubscribeToMore",I),t.component("ApolloMutation",T),t.component("ApolloMutation",T)))}x.install=B,x.version="3.1.2";var W=x,U=L,z=I,X=T,O=null;return"undefined"!=typeof window?O=window.Vue:"undefined"!=typeof global&&(O=global.Vue),O&&O.use(x),t.ApolloMutation=X,t.ApolloProvider=W,t.ApolloQuery=U,t.ApolloSubscribeToMore=z,t.default=x,t.install=B,t}({},gql);