@@ -2612,6 +2612,19 @@ var SmartApollo = function () {
26122612 value : function nextResult ( ) {
26132613 throw new Error ( 'Not implemented' ) ;
26142614 }
2615+ } , {
2616+ key : 'errorHandler' ,
2617+ value : function errorHandler ( ) {
2618+ var _options$error , _vm$$apollo$error , _vm$$apollo$provider$ ;
2619+
2620+ for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
2621+ args [ _key ] = arguments [ _key ] ;
2622+ }
2623+
2624+ this . options . error && ( _options$error = this . options . error ) . call . apply ( _options$error , [ this . vm ] . concat ( args ) ) ;
2625+ this . vm . $apollo . error && ( _vm$$apollo$error = this . vm . $apollo . error ) . call . apply ( _vm$$apollo$error , [ this . vm ] . concat ( args ) ) ;
2626+ this . vm . $apollo . provider . errorHandler && ( _vm$$apollo$provider$ = this . vm . $apollo . provider . errorHandler ) . call . apply ( _vm$$apollo$provider$ , [ this . vm ] . concat ( args ) ) ;
2627+ }
26152628 } , {
26162629 key : 'catchError' ,
26172630 value : function catchError ( error ) {
@@ -2654,9 +2667,7 @@ var SmartApollo = function () {
26542667 }
26552668 }
26562669
2657- if ( typeof this . options . error === 'function' ) {
2658- this . options . error . call ( this . vm , error ) ;
2659- }
2670+ this . errorHandler ( error ) ;
26602671 }
26612672 } , {
26622673 key : 'destroy' ,
@@ -2807,16 +2818,28 @@ var SmartQuery = function (_SmartApollo) {
28072818 get ( SmartQuery . prototype . __proto__ || Object . getPrototypeOf ( SmartQuery . prototype ) , 'catchError' , this ) . call ( this , error ) ;
28082819 this . loadingDone ( ) ;
28092820 }
2821+ } , {
2822+ key : 'watchLoading' ,
2823+ value : function watchLoading ( ) {
2824+ var _options$watchLoading , _vm$$apollo$watchLoad , _vm$$apollo$provider$2 ;
2825+
2826+ for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
2827+ args [ _key2 ] = arguments [ _key2 ] ;
2828+ }
2829+
2830+ this . options . watchLoading && ( _options$watchLoading = this . options . watchLoading ) . call . apply ( _options$watchLoading , [ this . vm ] . concat ( args ) ) ;
2831+ this . vm . $apollo . watchLoading && ( _vm$$apollo$watchLoad = this . vm . $apollo . watchLoading ) . call . apply ( _vm$$apollo$watchLoad , [ this . vm ] . concat ( args ) ) ;
2832+ this . vm . $apollo . provider . watchLoading && ( _vm$$apollo$provider$2 = this . vm . $apollo . provider . watchLoading ) . call . apply ( _vm$$apollo$provider$2 , [ this . vm ] . concat ( args ) ) ;
2833+ }
28102834 } , {
28112835 key : 'applyLoadingModifier' ,
28122836 value : function applyLoadingModifier ( value ) {
2813- if ( this . options . loadingKey ) {
2814- this . vm [ this . options . loadingKey ] += value ;
2837+ var loadingKey = this . loadingKey ;
2838+ if ( loadingKey && typeof this . vm [ loadingKey ] === 'number' ) {
2839+ this . vm [ loadingKey ] += value ;
28152840 }
28162841
2817- if ( this . options . watchLoading ) {
2818- this . options . watchLoading . call ( this . vm , value === 1 , value ) ;
2819- }
2842+ this . watchLoading ( value === 1 , value ) ;
28202843 }
28212844 } , {
28222845 key : 'loadingDone' ,
@@ -2909,6 +2932,11 @@ var SmartQuery = function (_SmartApollo) {
29092932 return ( _observer4 = this . observer ) . stopPolling . apply ( _observer4 , arguments ) ;
29102933 }
29112934 }
2935+ } , {
2936+ key : 'loadingKey' ,
2937+ get : function get$$1 ( ) {
2938+ return this . options . loadingKey || this . vm . $apollo . loadingKey ;
2939+ }
29122940 } ] ) ;
29132941 return SmartQuery ;
29142942} ( SmartApollo ) ;
@@ -2923,8 +2951,8 @@ var SmartSubscription = function (_SmartApollo2) {
29232951
29242952 classCallCheck ( this , SmartSubscription ) ;
29252953
2926- for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
2927- args [ _key ] = arguments [ _key ] ;
2954+ for ( var _len3 = arguments . length , args = Array ( _len3 ) , _key3 = 0 ; _key3 < _len3 ; _key3 ++ ) {
2955+ args [ _key3 ] = arguments [ _key3 ] ;
29282956 }
29292957
29302958 return _ret = ( _temp = ( _this6 = possibleConstructorReturn ( this , ( _ref = SmartSubscription . __proto__ || Object . getPrototypeOf ( SmartSubscription ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this6 ) , _this6 . type = 'subscription' , _this6 . vueApolloSpecialKeys = [ 'variables' , 'result' , 'error' , 'throttle' , 'debounce' , 'linkedQuery' ] , _temp ) , possibleConstructorReturn ( _this6 , _ret ) ;
@@ -2976,6 +3004,8 @@ var DollarApollo = function () {
29763004 this . queries = { } ;
29773005 this . subscriptions = { } ;
29783006 this . client = undefined ;
3007+ this . loadingKey = undefined ;
3008+ this . error = undefined ;
29793009 }
29803010
29813011 createClass ( DollarApollo , [ {
@@ -3168,6 +3198,9 @@ var ApolloProvider$1 = function () {
31683198 }
31693199 this . clients = options . clients || { } ;
31703200 this . clients . defaultClient = this . defaultClient = options . defaultClient ;
3201+ this . defaultOptions = options . defaultOptions ;
3202+ this . watchLoading = options . watchLoading ;
3203+ this . errorHandler = options . errorHandler ;
31713204
31723205 this . prefetchQueries = [ ] ;
31733206 }
@@ -3286,16 +3319,19 @@ var ApolloProvider$1 = function () {
32863319 result = prefetch ;
32873320 }
32883321
3289- var optVariables = queryOptions . variables ;
3290-
32913322 if ( ! result ) {
32923323 return Promise . resolve ( ) ;
3293- } else if ( prefetchType === 'boolean' && typeof optVariables !== 'undefined' ) {
3294- // Reuse `variables` option with `prefetch: true`
3295- if ( typeof optVariables === 'function' ) {
3296- variables = optVariables . call ( context ) ;
3324+ } else if ( prefetchType === 'boolean' ) {
3325+ var optVariables = queryOptions . variables ;
3326+ if ( typeof optVariables !== 'undefined' ) {
3327+ // Reuse `variables` option with `prefetch: true`
3328+ if ( typeof optVariables === 'function' ) {
3329+ variables = optVariables . call ( context ) ;
3330+ } else {
3331+ variables = optVariables ;
3332+ }
32973333 } else {
3298- variables = optVariables ;
3334+ variables = undefined ;
32993335 }
33003336 } else {
33013337 variables = result ;
@@ -3351,18 +3387,32 @@ function willPrefetch(component) {
33513387var keywords = [ '$subscribe' ] ;
33523388
33533389var prepare = function prepare ( ) {
3390+ var apolloProvider = void 0 ;
33543391 if ( this . $options . apolloProvider ) {
3355- this . _apolloProvider = this . $options . apolloProvider ;
3392+ apolloProvider = this . _apolloProvider = this . $options . apolloProvider ;
3393+ } else {
3394+ apolloProvider = this . $root . _apolloProvider ;
33563395 }
33573396
33583397 if ( this . _apolloPrepared ) return ;
33593398 this . _apolloPrepared = true ;
33603399
33613400 // Prepare properties
33623401 var apollo = this . $options . apollo ;
3402+
33633403 if ( apollo ) {
33643404 this . _apolloQueries = { } ;
33653405 this . _apolloInitData = { } ;
3406+ this . $apollo = new DollarApollo ( this ) ;
3407+
3408+ if ( ! apollo . $init ) {
3409+ apollo . $init = true ;
3410+
3411+ // Default options applied to `apollo` options
3412+ if ( apolloProvider . defaultOptions ) {
3413+ apollo = this . $options . apollo = Object . assign ( { } , apolloProvider . defaultOptions , apollo ) ;
3414+ }
3415+ }
33663416
33673417 // watchQuery
33683418 for ( var key in apollo ) {
@@ -3378,14 +3428,23 @@ var launch = function launch() {
33783428 if ( this . _apolloLaunched ) return ;
33793429 this . _apolloLaunched = true ;
33803430
3431+ var apollo = this . $options . apollo ;
3432+ if ( apollo ) {
3433+ defineReactiveSetter ( this . $apollo , 'skipAll' , apollo . $skipAll ) ;
3434+ defineReactiveSetter ( this . $apollo , 'skipAllQueries' , apollo . $skipAllQueries ) ;
3435+ defineReactiveSetter ( this . $apollo , 'skipAllSubscriptions' , apollo . $skipAllSubscriptions ) ;
3436+ defineReactiveSetter ( this . $apollo , 'client' , apollo . $client ) ;
3437+ defineReactiveSetter ( this . $apollo , 'loadingKey' , apollo . $loadingKey ) ;
3438+ defineReactiveSetter ( this . $apollo , 'error' , apollo . $error ) ;
3439+ }
3440+
33813441 if ( this . _apolloQueries ) {
33823442 // watchQuery
33833443 for ( var key in this . _apolloQueries ) {
33843444 this . $apollo . addSmartQuery ( key , this . _apolloQueries [ key ] ) ;
33853445 }
33863446 }
33873447
3388- var apollo = this . $options . apollo ;
33893448 if ( apollo ) {
33903449 if ( apollo . subscribe ) {
33913450 Globals . Vue . util . warn ( 'vue-apollo -> `subscribe` option is deprecated. Use the `$subscribe` option instead.' ) ;
@@ -3396,11 +3455,6 @@ var launch = function launch() {
33963455 this . $apollo . addSmartSubscription ( _key , apollo . $subscribe [ _key ] ) ;
33973456 }
33983457 }
3399-
3400- defineReactiveSetter ( this . $apollo , 'skipAll' , apollo . $skipAll ) ;
3401- defineReactiveSetter ( this . $apollo , 'skipAllQueries' , apollo . $skipAllQueries ) ;
3402- defineReactiveSetter ( this . $apollo , 'skipAllSubscriptions' , apollo . $skipAllSubscriptions ) ;
3403- defineReactiveSetter ( this . $apollo , 'client' , apollo . $client ) ;
34043458 }
34053459} ;
34063460
@@ -3438,16 +3492,6 @@ function install(Vue, options) {
34383492 return Object . assign ( map , merge ( toData , fromData ) ) ;
34393493 } ;
34403494
3441- // Lazy creation
3442- Object . defineProperty ( Vue . prototype , '$apollo' , {
3443- get : function get ( ) {
3444- if ( ! this . _apollo ) {
3445- this . _apollo = new DollarApollo ( this ) ;
3446- }
3447- return this . _apollo ;
3448- }
3449- } ) ;
3450-
34513495 Vue . mixin ( {
34523496
34533497 // Vue 1.x
0 commit comments