@@ -8340,7 +8340,7 @@ var VuexORMApollo = /** @class */ (function () {
8340
8340
var state = _a . state , dispatch = _a . dispatch ;
8341
8341
var id = _b . id , args = _b . args ;
8342
8342
return __awaiter ( this , void 0 , void 0 , function ( ) {
8343
- var model , data , mutationName , oldRecord ;
8343
+ var model , data , mutationName , newRecord , oldRecord ;
8344
8344
return __generator ( this , function ( _c ) {
8345
8345
switch ( _c . label ) {
8346
8346
case 0 :
@@ -8352,7 +8352,7 @@ var VuexORMApollo = /** @class */ (function () {
8352
8352
mutationName = "create" + upcaseFirstLetter ( model . singularName ) ;
8353
8353
return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8354
8354
case 1 :
8355
- _c . sent ( ) ;
8355
+ newRecord = _c . sent ( ) ;
8356
8356
oldRecord = model . baseModel . getters ( 'find' ) ( id ) ;
8357
8357
if ( ! ( oldRecord && ! oldRecord . $isPersisted ) ) return [ 3 /*break*/ , 3 ] ;
8358
8358
// The server generated another ID, this is very likely to happen.
@@ -8363,9 +8363,7 @@ var VuexORMApollo = /** @class */ (function () {
8363
8363
case 2 :
8364
8364
_c . sent ( ) ;
8365
8365
_c . label = 3 ;
8366
- case 3 :
8367
- // TODO is this save?
8368
- return [ 2 /*return*/ , model . baseModel . getters ( 'query' ) ( ) . withAll ( ) . last ( ) ] ;
8366
+ case 3 : return [ 2 /*return*/ , newRecord ] ;
8369
8367
case 4 : return [ 2 /*return*/ ] ;
8370
8368
}
8371
8369
} ) ;
@@ -8416,20 +8414,15 @@ var VuexORMApollo = /** @class */ (function () {
8416
8414
return __awaiter ( this , void 0 , void 0 , function ( ) {
8417
8415
var model , mutationName ;
8418
8416
return __generator ( this , function ( _c ) {
8419
- switch ( _c . label ) {
8420
- case 0 :
8421
- if ( ! data ) return [ 3 /*break*/ , 2 ] ;
8422
- model = this . context . getModel ( state . $name ) ;
8423
- args = args || { } ;
8424
- args [ 'id' ] = data . id ;
8425
- args [ model . singularName ] = this . queryBuilder . transformOutgoingData ( model , data ) ;
8426
- mutationName = "update" + upcaseFirstLetter ( model . singularName ) ;
8427
- return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8428
- case 1 :
8429
- _c . sent ( ) ;
8430
- return [ 2 /*return*/ , model . baseModel . getters ( 'find' ) ( data . id ) ] ;
8431
- case 2 : return [ 2 /*return*/ ] ;
8417
+ if ( data ) {
8418
+ model = this . context . getModel ( state . $name ) ;
8419
+ args = args || { } ;
8420
+ args [ 'id' ] = data . id ;
8421
+ args [ model . singularName ] = this . queryBuilder . transformOutgoingData ( model , data ) ;
8422
+ mutationName = "update" + upcaseFirstLetter ( model . singularName ) ;
8423
+ return [ 2 /*return*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8432
8424
}
8425
+ return [ 2 /*return*/ ] ;
8433
8426
} ) ;
8434
8427
} ) ;
8435
8428
} ;
@@ -8470,7 +8463,7 @@ var VuexORMApollo = /** @class */ (function () {
8470
8463
*/
8471
8464
VuexORMApollo . prototype . mutate = function ( name , variables , dispatch , model , multiple ) {
8472
8465
return __awaiter ( this , void 0 , void 0 , function ( ) {
8473
- var id , query , newData ;
8466
+ var id , query , newData , insertedData ;
8474
8467
return __generator ( this , function ( _a ) {
8475
8468
switch ( _a . label ) {
8476
8469
case 0 :
@@ -8483,8 +8476,8 @@ var VuexORMApollo = /** @class */ (function () {
8483
8476
if ( ! ( name !== "delete" + upcaseFirstLetter ( model . singularName ) ) ) return [ 3 /*break*/ , 3 ] ;
8484
8477
return [ 4 /*yield*/ , this . insertData ( newData , dispatch ) ] ;
8485
8478
case 2 :
8486
- _a . sent ( ) ;
8487
- return [ 2 /*return*/ , true ] ; // FIXME RETURN THE NEW RECORD!!
8479
+ insertedData = _a . sent ( ) ;
8480
+ return [ 2 /*return*/ , insertedData [ model . pluralName ] [ 0 ] ] ;
8488
8481
case 3 : return [ 2 /*return*/ , true ] ;
8489
8482
case 4 : return [ 2 /*return*/ ] ;
8490
8483
}
@@ -8535,22 +8528,29 @@ var VuexORMApollo = /** @class */ (function () {
8535
8528
VuexORMApollo . prototype . insertData = function ( data , dispatch ) {
8536
8529
return __awaiter ( this , void 0 , void 0 , function ( ) {
8537
8530
var _this = this ;
8531
+ var insertedData ;
8538
8532
return __generator ( this , function ( _a ) {
8533
+ insertedData = { } ;
8539
8534
Object . keys ( data ) . forEach ( function ( key ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
8540
- var value ;
8535
+ var value , newData ;
8541
8536
return __generator ( this , function ( _a ) {
8542
8537
switch ( _a . label ) {
8543
8538
case 0 :
8544
8539
value = data [ key ] ;
8545
8540
this . context . logger . log ( 'Inserting records' , value ) ;
8546
8541
return [ 4 /*yield*/ , dispatch ( 'insertOrUpdate' , { data : value } ) ] ;
8547
8542
case 1 :
8548
- _a . sent ( ) ;
8543
+ newData = _a . sent ( ) ;
8544
+ Object . keys ( newData ) . forEach ( function ( dataKey ) {
8545
+ if ( ! insertedData [ dataKey ] )
8546
+ insertedData [ dataKey ] = [ ] ;
8547
+ insertedData [ dataKey ] = insertedData [ dataKey ] . concat ( newData [ dataKey ] ) ;
8548
+ } ) ;
8549
8549
return [ 2 /*return*/ ] ;
8550
8550
}
8551
8551
} ) ;
8552
8552
} ) ; } ) ;
8553
- return [ 2 /*return*/ ] ;
8553
+ return [ 2 /*return*/ , insertedData ] ;
8554
8554
} ) ;
8555
8555
} ) ;
8556
8556
} ;
0 commit comments