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 () {
93359335 /**
93369336 * Transforms outgoing data. Use for variables param.
93379337 *
9338- * Omits relations and id fields.
9338+ * Omits relations and some fields.
93399339 *
93409340 * @param model
93419341 * @param {Data } data
93429342 * @returns {Data }
93439343 */
93449344 QueryBuilder . prototype . transformOutgoingData = function ( model , data ) {
9345+ var _this = this ;
93459346 var relations = model . getRelations ( ) ;
93469347 var returnValue = { } ;
93479348 Object . keys ( data ) . forEach ( function ( key ) {
93489349 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+ }
93529359 }
93539360 } ) ;
93549361 return returnValue ;
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ export default class QueryBuilder {
125125 /**
126126 * Transforms outgoing data. Use for variables param.
127127 *
128- * Omits relations and id fields.
128+ * Omits relations and some fields.
129129 *
130130 * @param model
131131 * @param {Data } data
@@ -138,9 +138,14 @@ export default class QueryBuilder {
138138 Object . keys ( data ) . forEach ( ( key ) => {
139139 const value = data [ key ] ;
140140
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+ }
144149 }
145150 } ) ;
146151
Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ query Users {
300300 await store . dispatch ( 'entities/users/persist' , { id : 1 } ) ;
301301 } ) ;
302302
303- expect ( request . variables ) . toEqual ( { user : { name : 'Charlie Brown' } } ) ;
303+ expect ( request . variables ) . toEqual ( { user : { id : 1 , name : 'Charlie Brown' } } ) ;
304304 expect ( request . query ) . toEqual ( `
305305mutation CreateUser($user: UserInput!) {
306306 createUser(user: $user) {
@@ -333,7 +333,7 @@ mutation CreateUser($user: UserInput!) {
333333 await store . dispatch ( 'entities/users/push' , { data : user } ) ;
334334 } ) ;
335335
336- expect ( request . variables ) . toEqual ( { id : 1 , user : { name : 'Snoopy' } } ) ;
336+ expect ( request . variables ) . toEqual ( { id : 1 , user : { id : 1 , name : 'Snoopy' } } ) ;
337337 expect ( request . query ) . toEqual ( `
338338mutation UpdateUser($id: ID!, $user: UserInput!) {
339339 updateUser(id: $id, user: $user) {
Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ describe('QueryBuilder', () => {
187187 it ( 'transforms models to a useful data hashmap' , ( ) => {
188188 const user = store . getters [ 'entities/users/query' ] ( ) . first ( ) ;
189189 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' } ) ;
191191 } ) ;
192192 } ) ;
193193
You can’t perform that action at this time.
0 commit comments