@@ -9318,9 +9318,11 @@ var QueryBuilder = /** @class */ (function () {
9318
9318
args = args ? JSON . parse ( JSON . stringify ( args ) ) : { } ;
9319
9319
if ( ! args )
9320
9320
throw new Error ( 'args is undefined' ) ;
9321
- if ( args [ model . singularName ] && typeof args [ model . singularName ] === 'object' ) {
9322
- args [ model . singularName ] = { __type : upcaseFirstLetter ( model . singularName ) } ;
9323
- }
9321
+ Object . keys ( args ) . forEach ( function ( key ) {
9322
+ if ( args && args [ key ] && typeof args [ key ] === 'object' ) {
9323
+ args [ key ] = { __type : upcaseFirstLetter ( key ) } ;
9324
+ }
9325
+ } ) ;
9324
9326
// multiple
9325
9327
multiple = multiple === undefined ? ! args [ 'id' ] : multiple ;
9326
9328
// name
@@ -9351,14 +9353,17 @@ var QueryBuilder = /** @class */ (function () {
9351
9353
if ( ( ! relations . has ( key ) || relations . get ( key ) instanceof _this . context . components . BelongsTo ) &&
9352
9354
! key . startsWith ( '$' ) && value !== null ) {
9353
9355
if ( value instanceof Array ) {
9356
+ // Iterate over all fields and transform them if value is an array
9354
9357
var arrayModel_1 = _this . getModel ( inflection . singularize ( key ) ) ;
9355
9358
returnValue [ key ] = value . map ( function ( v ) { return _this . transformOutgoingData ( arrayModel_1 || model , v ) ; } ) ;
9356
9359
}
9357
- else if ( relations . get ( key ) instanceof _this . context . components . BelongsTo ) {
9360
+ else if ( typeof value === 'object' && _this . context . getModel ( inflection . singularize ( key ) , true ) ) {
9361
+ // Value is a record, transform that too
9358
9362
var relatedModel = _this . getModel ( inflection . singularize ( key ) ) ;
9359
9363
returnValue [ key ] = _this . transformOutgoingData ( relatedModel || model , value ) ;
9360
9364
}
9361
9365
else {
9366
+ // In any other case just let the value be what ever it is
9362
9367
returnValue [ key ] = value ;
9363
9368
}
9364
9369
}
@@ -9939,16 +9944,16 @@ var VuexORMApollo = /** @class */ (function () {
9939
9944
VuexORMApollo . prototype . fetch = function ( _a , params ) {
9940
9945
var state = _a . state , dispatch = _a . dispatch ;
9941
9946
return __awaiter ( this , void 0 , void 0 , function ( ) {
9942
- var filter , bypassCache , multiple , model , name , query , data ;
9947
+ var model , filter , bypassCache , multiple , name , query , data ;
9943
9948
return __generator ( this , function ( _b ) {
9944
9949
switch ( _b . label ) {
9945
9950
case 0 :
9946
- filter = params ? params . filter || { } : { } ;
9951
+ model = this . context . getModel ( state . $name ) ;
9952
+ filter = params && params . filter ? this . queryBuilder . transformOutgoingData ( model , params . filter ) : { } ;
9947
9953
bypassCache = params && params . bypassCache ;
9948
9954
multiple = ! filter [ 'id' ] ;
9949
- model = this . context . getModel ( state . $name ) ;
9950
9955
name = "" + ( multiple ? model . pluralName : model . singularName ) ;
9951
- query = this . queryBuilder . buildQuery ( 'query' , model , name , filter ) ;
9956
+ query = this . queryBuilder . buildQuery ( 'query' , model , name , filter , multiple ) ;
9952
9957
return [ 4 /*yield*/ , this . apolloRequest ( model , query , filter , false , bypassCache ) ] ;
9953
9958
case 1 :
9954
9959
data = _b . sent ( ) ;
0 commit comments