@@ -8340,7 +8340,7 @@ var VuexORMApollo = /** @class */ (function () {
83408340 var state = _a . state , dispatch = _a . dispatch ;
83418341 var id = _b . id , args = _b . args ;
83428342 return __awaiter ( this , void 0 , void 0 , function ( ) {
8343- var model , data , mutationName , oldRecord ;
8343+ var model , data , mutationName , newRecord , oldRecord ;
83448344 return __generator ( this , function ( _c ) {
83458345 switch ( _c . label ) {
83468346 case 0 :
@@ -8352,7 +8352,7 @@ var VuexORMApollo = /** @class */ (function () {
83528352 mutationName = "create" + upcaseFirstLetter ( model . singularName ) ;
83538353 return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
83548354 case 1 :
8355- _c . sent ( ) ;
8355+ newRecord = _c . sent ( ) ;
83568356 oldRecord = model . baseModel . getters ( 'find' ) ( id ) ;
83578357 if ( ! ( oldRecord && ! oldRecord . $isPersisted ) ) return [ 3 /*break*/ , 3 ] ;
83588358 // The server generated another ID, this is very likely to happen.
@@ -8363,9 +8363,7 @@ var VuexORMApollo = /** @class */ (function () {
83638363 case 2 :
83648364 _c . sent ( ) ;
83658365 _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 ] ;
83698367 case 4 : return [ 2 /*return*/ ] ;
83708368 }
83718369 } ) ;
@@ -8416,20 +8414,15 @@ var VuexORMApollo = /** @class */ (function () {
84168414 return __awaiter ( this , void 0 , void 0 , function ( ) {
84178415 var model , mutationName ;
84188416 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 ) ] ;
84328424 }
8425+ return [ 2 /*return*/ ] ;
84338426 } ) ;
84348427 } ) ;
84358428 } ;
@@ -8470,7 +8463,7 @@ var VuexORMApollo = /** @class */ (function () {
84708463 */
84718464 VuexORMApollo . prototype . mutate = function ( name , variables , dispatch , model , multiple ) {
84728465 return __awaiter ( this , void 0 , void 0 , function ( ) {
8473- var id , query , newData ;
8466+ var id , query , newData , insertedData ;
84748467 return __generator ( this , function ( _a ) {
84758468 switch ( _a . label ) {
84768469 case 0 :
@@ -8483,8 +8476,8 @@ var VuexORMApollo = /** @class */ (function () {
84838476 if ( ! ( name !== "delete" + upcaseFirstLetter ( model . singularName ) ) ) return [ 3 /*break*/ , 3 ] ;
84848477 return [ 4 /*yield*/ , this . insertData ( newData , dispatch ) ] ;
84858478 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 ] ] ;
84888481 case 3 : return [ 2 /*return*/ , true ] ;
84898482 case 4 : return [ 2 /*return*/ ] ;
84908483 }
@@ -8535,22 +8528,29 @@ var VuexORMApollo = /** @class */ (function () {
85358528 VuexORMApollo . prototype . insertData = function ( data , dispatch ) {
85368529 return __awaiter ( this , void 0 , void 0 , function ( ) {
85378530 var _this = this ;
8531+ var insertedData ;
85388532 return __generator ( this , function ( _a ) {
8533+ insertedData = { } ;
85398534 Object . keys ( data ) . forEach ( function ( key ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
8540- var value ;
8535+ var value , newData ;
85418536 return __generator ( this , function ( _a ) {
85428537 switch ( _a . label ) {
85438538 case 0 :
85448539 value = data [ key ] ;
85458540 this . context . logger . log ( 'Inserting records' , value ) ;
85468541 return [ 4 /*yield*/ , dispatch ( 'insertOrUpdate' , { data : value } ) ] ;
85478542 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+ } ) ;
85498549 return [ 2 /*return*/ ] ;
85508550 }
85518551 } ) ;
85528552 } ) ; } ) ;
8553- return [ 2 /*return*/ ] ;
8553+ return [ 2 /*return*/ , insertedData ] ;
85548554 } ) ;
85558555 } ) ;
85568556 } ;
0 commit comments