@@ -7867,7 +7867,11 @@ var QueryBuilder = /** @class */ (function () {
7867
7867
this . context . logger . log ( 'Transformed data:' , result ) ;
7868
7868
this . context . logger . groupEnd ( ) ;
7869
7869
}
7870
- return result ;
7870
+ else {
7871
+ result [ '$isPersisted' ] = true ;
7872
+ }
7873
+ // MAke sure this is really a plain JS object. We had some issues in testing here.
7874
+ return JSON . parse ( JSON . stringify ( result ) ) ;
7871
7875
} ;
7872
7876
/**
7873
7877
* Generates the arguments string for a graphql query based on a given map.
@@ -8144,6 +8148,12 @@ var Context = /** @class */ (function () {
8144
8148
throw new Error ( 'database param is required to initialize vuex-orm-apollo!' ) ;
8145
8149
}
8146
8150
this . collectModels ( ) ;
8151
+ this . logger . group ( 'Context setup' ) ;
8152
+ this . logger . log ( 'components' , this . components ) ;
8153
+ this . logger . log ( 'options' , this . options ) ;
8154
+ this . logger . log ( 'database' , this . database ) ;
8155
+ this . logger . log ( 'models' , this . models ) ;
8156
+ this . logger . groupEnd ( ) ;
8147
8157
}
8148
8158
/**
8149
8159
* Returns a model by name
@@ -8168,8 +8178,17 @@ var Context = /** @class */ (function () {
8168
8178
this . database . entities . forEach ( function ( entity ) {
8169
8179
var model = new Model ( entity . model , _this ) ;
8170
8180
_this . models . set ( model . singularName , model ) ;
8181
+ _this . augmentModel ( model ) ;
8171
8182
} ) ;
8172
8183
} ;
8184
+ Context . prototype . augmentModel = function ( model ) {
8185
+ var originalFieldGenerator = model . baseModel . fields . bind ( model . baseModel ) ;
8186
+ model . baseModel . fields = function ( ) {
8187
+ var originalFields = originalFieldGenerator ( ) ;
8188
+ originalFields [ '$isPersisted' ] = model . baseModel . attr ( false ) ;
8189
+ return originalFields ;
8190
+ } ;
8191
+ } ;
8173
8192
return Context ;
8174
8193
} ( ) ) ;
8175
8194
@@ -8308,7 +8327,7 @@ var VuexORMApollo = /** @class */ (function () {
8308
8327
var state = _a . state , dispatch = _a . dispatch ;
8309
8328
var id = _b . id , args = _b . args ;
8310
8329
return __awaiter ( this , void 0 , void 0 , function ( ) {
8311
- var model , data , mutationName ;
8330
+ var model , data , mutationName , record ;
8312
8331
return __generator ( this , function ( _c ) {
8313
8332
switch ( _c . label ) {
8314
8333
case 0 :
@@ -8321,8 +8340,10 @@ var VuexORMApollo = /** @class */ (function () {
8321
8340
return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8322
8341
case 1 :
8323
8342
_c . sent ( ) ;
8324
- // TODO is this really necessary?
8325
- return [ 2 /*return*/ , model . baseModel . getters ( 'find' ) ( id ) ] ;
8343
+ record = model . baseModel . getters ( 'find' ) ( id ) ;
8344
+ record . $isPersisted = true ;
8345
+ record . $dispatch ( 'update' , { where : record . id , data : record } ) ;
8346
+ return [ 2 /*return*/ , record ] ;
8326
8347
case 2 : return [ 2 /*return*/ ] ;
8327
8348
}
8328
8349
} ) ;
0 commit comments