@@ -10551,22 +10551,32 @@ var Mutate = /** @class */ (function (_super) {
10551
10551
/**
10552
10552
* @param {any } state The Vuex state
10553
10553
* @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?
10554
10556
* @param {Arguments } args Arguments for the mutation. Must contain a 'mutation' field.
10555
10557
* @returns {Promise<Data> } The new record if any
10556
10558
*/
10557
- Mutate . call = function ( _a , args ) {
10559
+ Mutate . call = function ( _a , _b ) {
10558
10560
var state = _a . state , dispatch = _a . dispatch ;
10561
+ var args = _b . args , multiple = _b . multiple , name = _b . name ;
10559
10562
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*/ ] ;
10570
10580
} ) ;
10571
10581
} ) ;
10572
10582
} ;
@@ -10824,30 +10834,34 @@ var Query = /** @class */ (function (_super) {
10824
10834
/**
10825
10835
* @param {any } state The Vuex state
10826
10836
* @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
10828
10841
* @returns {Promise<Data> } The fetched records as hash
10829
10842
*/
10830
- Query . call = function ( _a , params ) {
10843
+ Query . call = function ( _a , _b ) {
10831
10844
var state = _a . state , dispatch = _a . dispatch ;
10845
+ var name = _b . name , multiple = _b . multiple , filter = _b . filter , bypassCache = _b . bypassCache ;
10832
10846
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 ) {
10836
10850
case 0 :
10837
- if ( ! ( params && params . query ) ) return [ 3 /*break*/ , 2 ] ;
10851
+ if ( ! name ) return [ 3 /*break*/ , 2 ] ;
10838
10852
context = Context . getInstance ( ) ;
10839
10853
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 ) ;
10845
10859
return [ 4 /*yield*/ , context . apollo . request ( model , query , filter , false , bypassCache ) ] ;
10846
10860
case 1 :
10847
- data = _b . sent ( ) ;
10861
+ data = _c . sent ( ) ;
10848
10862
// Insert incoming data into the store
10849
10863
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" ) ;
10851
10865
}
10852
10866
} ) ;
10853
10867
} ) ;
@@ -11107,32 +11121,35 @@ var VuexORMApollo = /** @class */ (function () {
11107
11121
} ) ;
11108
11122
} ) ;
11109
11123
} ;
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 ;
11112
11126
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 } ) ] ;
11115
11129
} ) ;
11116
11130
} ) ;
11117
11131
} ;
11118
11132
// Register model convenience methods
11119
11133
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 ;
11121
11136
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 } ) ] ;
11126
11142
} ) ;
11127
11143
} ) ;
11128
11144
} ;
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 ;
11131
11147
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 || { } ;
11133
11150
if ( ! filter [ 'id' ] )
11134
11151
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 } ) ] ;
11136
11153
} ) ;
11137
11154
} ) ;
11138
11155
} ;
0 commit comments