File tree Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -9335,20 +9335,27 @@ var QueryBuilder = /** @class */ (function () {
9335
9335
/**
9336
9336
* Transforms outgoing data. Use for variables param.
9337
9337
*
9338
- * Omits relations and id fields.
9338
+ * Omits relations and some fields.
9339
9339
*
9340
9340
* @param model
9341
9341
* @param {Data } data
9342
9342
* @returns {Data }
9343
9343
*/
9344
9344
QueryBuilder . prototype . transformOutgoingData = function ( model , data ) {
9345
+ var _this = this ;
9345
9346
var relations = model . getRelations ( ) ;
9346
9347
var returnValue = { } ;
9347
9348
Object . keys ( data ) . forEach ( function ( key ) {
9348
9349
var value = data [ key ] ;
9349
- // Ignore IDs and connections and empty fields
9350
- if ( ! relations . has ( key ) && ! key . startsWith ( '$' ) && key !== 'id' && value !== null ) {
9351
- returnValue [ key ] = value ;
9350
+ // Ignore connections and empty fields
9351
+ if ( ! relations . has ( key ) && ! key . startsWith ( '$' ) && value !== null ) {
9352
+ if ( value instanceof Array ) {
9353
+ var arrayModel_1 = _this . getModel ( inflection . singularize ( key ) ) ;
9354
+ returnValue [ key ] = value . map ( function ( v ) { return _this . transformOutgoingData ( arrayModel_1 || model , v ) ; } ) ;
9355
+ }
9356
+ else {
9357
+ returnValue [ key ] = value ;
9358
+ }
9352
9359
}
9353
9360
} ) ;
9354
9361
return returnValue ;
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ export default class QueryBuilder {
125
125
/**
126
126
* Transforms outgoing data. Use for variables param.
127
127
*
128
- * Omits relations and id fields.
128
+ * Omits relations and some fields.
129
129
*
130
130
* @param model
131
131
* @param {Data } data
@@ -138,9 +138,14 @@ export default class QueryBuilder {
138
138
Object . keys ( data ) . forEach ( ( key ) => {
139
139
const value = data [ key ] ;
140
140
141
- // Ignore IDs and connections and empty fields
142
- if ( ! relations . has ( key ) && ! key . startsWith ( '$' ) && key !== 'id' && value !== null ) {
143
- returnValue [ key ] = value ;
141
+ // Ignore connections and empty fields
142
+ if ( ! relations . has ( key ) && ! key . startsWith ( '$' ) && value !== null ) {
143
+ if ( value instanceof Array ) {
144
+ const arrayModel = this . getModel ( inflection . singularize ( key ) ) ;
145
+ returnValue [ key ] = value . map ( ( v ) => this . transformOutgoingData ( arrayModel || model , v ) ) ;
146
+ } else {
147
+ returnValue [ key ] = value ;
148
+ }
144
149
}
145
150
} ) ;
146
151
Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ query Users {
300
300
await store . dispatch ( 'entities/users/persist' , { id : 1 } ) ;
301
301
} ) ;
302
302
303
- expect ( request . variables ) . toEqual ( { user : { name : 'Charlie Brown' } } ) ;
303
+ expect ( request . variables ) . toEqual ( { user : { id : 1 , name : 'Charlie Brown' } } ) ;
304
304
expect ( request . query ) . toEqual ( `
305
305
mutation CreateUser($user: UserInput!) {
306
306
createUser(user: $user) {
@@ -333,7 +333,7 @@ mutation CreateUser($user: UserInput!) {
333
333
await store . dispatch ( 'entities/users/push' , { data : user } ) ;
334
334
} ) ;
335
335
336
- expect ( request . variables ) . toEqual ( { id : 1 , user : { name : 'Snoopy' } } ) ;
336
+ expect ( request . variables ) . toEqual ( { id : 1 , user : { id : 1 , name : 'Snoopy' } } ) ;
337
337
expect ( request . query ) . toEqual ( `
338
338
mutation UpdateUser($id: ID!, $user: UserInput!) {
339
339
updateUser(id: $id, user: $user) {
Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ describe('QueryBuilder', () => {
187
187
it ( 'transforms models to a useful data hashmap' , ( ) => {
188
188
const user = store . getters [ 'entities/users/query' ] ( ) . first ( ) ;
189
189
const transformedData = queryBuilder . transformOutgoingData ( vuexOrmApollo . context . getModel ( 'user' ) , user ) ;
190
- expect ( transformedData ) . toEqual ( { name : 'Charlie Brown' } ) ;
190
+ expect ( transformedData ) . toEqual ( { id : 1 , name : 'Charlie Brown' } ) ;
191
191
} ) ;
192
192
} ) ;
193
193
You can’t perform that action at this time.
0 commit comments