@@ -10551,22 +10551,32 @@ var Mutate = /** @class */ (function (_super) {
1055110551 /**
1055210552 * @param {any } state The Vuex state
1055310553 * @param {DispatchFunction } dispatch Vuex Dispatch method for the model
10554+ * @param {string } name Name of the query
10555+ * @param {boolean } multiple Fetch one or multiple?
1055410556 * @param {Arguments } args Arguments for the mutation. Must contain a 'mutation' field.
1055510557 * @returns {Promise<Data> } The new record if any
1055610558 */
10557- Mutate . call = function ( _a , args ) {
10559+ Mutate . call = function ( _a , _b ) {
1055810560 var state = _a . state , dispatch = _a . dispatch ;
10561+ var args = _b . args , multiple = _b . multiple , name = _b . name ;
1055910562 return __awaiter$5 ( this , void 0 , void 0 , function ( ) {
10560- var model , mutationName ;
10561- return __generator$5 ( this , function ( _b ) {
10562- model = this . getModelFromState ( state ) ;
10563- mutationName = args [ 'mutation' ] ;
10564- delete args [ 'mutation' ] ;
10565- // There could be anything in the args, but we have to be sure that all records are gone through
10566- // transformOutgoingData()
10567- this . transformArgs ( args ) ;
10568- // Send the mutation
10569- return [ 2 /*return*/ , Action . mutation ( mutationName , args , dispatch , model , ! args [ 'id' ] ) ] ;
10563+ var model ;
10564+ return __generator$5 ( this , function ( _c ) {
10565+ if ( name ) {
10566+ model = this . getModelFromState ( state ) ;
10567+ args = this . prepareArgs ( args ) ;
10568+ // There could be anything in the args, but we have to be sure that all records are gone through
10569+ // transformOutgoingData()
10570+ this . transformArgs ( args ) ;
10571+ if ( multiple === undefined )
10572+ multiple = ! args [ 'id' ] ;
10573+ // Send the mutation
10574+ return [ 2 /*return*/ , Action . mutation ( name , args , dispatch , model , multiple ) ] ;
10575+ }
10576+ else {
10577+ throw new Error ( "The mutate action requires the mutation name ('mutation') to be set" ) ;
10578+ }
10579+ return [ 2 /*return*/ ] ;
1057010580 } ) ;
1057110581 } ) ;
1057210582 } ;
@@ -10824,30 +10834,34 @@ var Query = /** @class */ (function (_super) {
1082410834 /**
1082510835 * @param {any } state The Vuex state
1082610836 * @param {DispatchFunction } dispatch Vuex Dispatch method for the model
10827- * @param {ActionParams } params Optional params to send with the query
10837+ * @param {string } name Name of the query
10838+ * @param {boolean } multiple Fetch one or multiple?
10839+ * @param {object } filter Filter object (arguments)
10840+ * @param {boolean } bypassCache Whether to bypass the cache
1082810841 * @returns {Promise<Data> } The fetched records as hash
1082910842 */
10830- Query . call = function ( _a , params ) {
10843+ Query . call = function ( _a , _b ) {
1083110844 var state = _a . state , dispatch = _a . dispatch ;
10845+ var name = _b . name , multiple = _b . multiple , filter = _b . filter , bypassCache = _b . bypassCache ;
1083210846 return __awaiter$8 ( this , void 0 , void 0 , function ( ) {
10833- var context , model , filter , bypassCache , multiple , name_1 , query , data ;
10834- return __generator$8 ( this , function ( _b ) {
10835- switch ( _b . label ) {
10847+ var context , model , query , data ;
10848+ return __generator$8 ( this , function ( _c ) {
10849+ switch ( _c . label ) {
1083610850 case 0 :
10837- if ( ! ( params && params . query ) ) return [ 3 /*break*/ , 2 ] ;
10851+ if ( ! name ) return [ 3 /*break*/ , 2 ] ;
1083810852 context = Context . getInstance ( ) ;
1083910853 model = this . getModelFromState ( state ) ;
10840- filter = params && params . filter ? Transformer . transformOutgoingData ( model , params . filter ) : { } ;
10841- bypassCache = params && params . bypassCache ;
10842- multiple = ! filter [ 'id' ] ;
10843- name_1 = params . query ;
10844- query = QueryBuilder . buildQuery ( 'query' , model , name_1 , filter , multiple , false ) ;
10854+ // Filter
10855+ filter = filter ? Transformer . transformOutgoingData ( model , filter ) : { } ;
10856+ if ( multiple === undefined )
10857+ multiple = ! filter [ 'id' ] ;
10858+ query = QueryBuilder . buildQuery ( 'query' , model , name , filter , multiple , false ) ;
1084510859 return [ 4 /*yield*/ , context . apollo . request ( model , query , filter , false , bypassCache ) ] ;
1084610860 case 1 :
10847- data = _b . sent ( ) ;
10861+ data = _c . sent ( ) ;
1084810862 // Insert incoming data into the store
1084910863 return [ 2 /*return*/ , Store . insertData ( data , dispatch ) ] ;
10850- case 2 : throw new Error ( "The customQuery action requires the query name ('query ') to be set" ) ;
10864+ case 2 : throw new Error ( "The customQuery action requires the query name ('name ') to be set" ) ;
1085110865 }
1085210866 } ) ;
1085310867 } ) ;
@@ -11107,32 +11121,35 @@ var VuexORMApollo = /** @class */ (function () {
1110711121 } ) ;
1110811122 } ) ;
1110911123 } ;
11110- context . components . Model . customQuery = function ( query , filter , bypassCache ) {
11111- if ( bypassCache === void 0 ) { bypassCache = false ; }
11124+ context . components . Model . customQuery = function ( _a ) {
11125+ var name = _a . name , filter = _a . filter , multiple = _a . multiple , bypassCache = _a . bypassCache ;
1111211126 return __awaiter$11 ( this , void 0 , void 0 , function ( ) {
11113- return __generator$11 ( this , function ( _a ) {
11114- return [ 2 /*return*/ , this . dispatch ( 'query' , { query : query , filter : filter , bypassCache : bypassCache } ) ] ;
11127+ return __generator$11 ( this , function ( _b ) {
11128+ return [ 2 /*return*/ , this . dispatch ( 'query' , { name : name , filter : filter , multiple : multiple , bypassCache : bypassCache } ) ] ;
1111511129 } ) ;
1111611130 } ) ;
1111711131 } ;
1111811132 // Register model convenience methods
1111911133 var model = context . components . Model . prototype ;
11120- model . $mutate = function ( params ) {
11134+ model . $mutate = function ( _a ) {
11135+ var name = _a . name , args = _a . args , multiple = _a . multiple ;
1112111136 return __awaiter$11 ( this , void 0 , void 0 , function ( ) {
11122- return __generator$11 ( this , function ( _a ) {
11123- if ( ! params [ 'id' ] )
11124- params [ 'id' ] = this . id ;
11125- return [ 2 /*return*/ , this . $dispatch ( 'mutate' , params ) ] ;
11137+ return __generator$11 ( this , function ( _b ) {
11138+ args = args || { } ;
11139+ if ( ! args [ 'id' ] )
11140+ args [ 'id' ] = this . id ;
11141+ return [ 2 /*return*/ , this . $dispatch ( 'mutate' , { name : name , args : args , multiple : multiple } ) ] ;
1112611142 } ) ;
1112711143 } ) ;
1112811144 } ;
11129- model . $customQuery = function ( query , filter , bypassCache ) {
11130- if ( bypassCache === void 0 ) { bypassCache = false ; }
11145+ model . $customQuery = function ( _a ) {
11146+ var name = _a . name , filter = _a . filter , multiple = _a . multiple , bypassCache = _a . bypassCache ;
1113111147 return __awaiter$11 ( this , void 0 , void 0 , function ( ) {
11132- return __generator$11 ( this , function ( _a ) {
11148+ return __generator$11 ( this , function ( _b ) {
11149+ filter = filter || { } ;
1113311150 if ( ! filter [ 'id' ] )
1113411151 filter [ 'id' ] = this . id ;
11135- return [ 2 /*return*/ , this . $dispatch ( 'query' , { query : query , filter : filter , bypassCache : bypassCache } ) ] ;
11152+ return [ 2 /*return*/ , this . $dispatch ( 'query' , { name : name , filter : filter , multiple : multiple , bypassCache : bypassCache } ) ] ;
1113611153 } ) ;
1113711154 } ) ;
1113811155 } ;
0 commit comments