@@ -10,6 +10,7 @@ import {
1010 singularize
1111} from "../support/utils" ;
1212import { ConnectionMode } from "../adapters/adapter" ;
13+ import { GraphQLType , GraphQLField } from "../support/interfaces" ;
1314
1415/**
1516 * This class provides methods to transform incoming data from GraphQL in to a format Vuex-ORM understands and
@@ -32,13 +33,15 @@ export default class Transformer {
3233 model : Model ,
3334 data : Data ,
3435 read : boolean ,
36+ inputType ?: GraphQLType | null ,
3537 whitelist ?: Array < String > ,
3638 outgoingRecords ?: Map < string , Array < string > > ,
3739 recursiveCall ?: boolean
3840 ) : Data {
3941 const context = Context . getInstance ( ) ;
4042 const relations : Map < string , Relation > = model . getRelations ( ) ;
4143 const returnValue : Data = { } as Data ;
44+ const inputFields = inputType ? inputType . inputFields : undefined ;
4245 if ( outgoingRecords === undefined ) outgoingRecords = new Map < string , Array < string > > ( ) ;
4346 if ( recursiveCall === undefined ) recursiveCall = false ;
4447
@@ -64,7 +67,8 @@ export default class Transformer {
6467 key ,
6568 value ,
6669 model ,
67- whitelist
70+ whitelist ,
71+ inputFields
6872 )
6973 ) {
7074 let relatedModel = Model . getRelatedModel ( relations . get ( key ) ! ) ;
@@ -81,6 +85,7 @@ export default class Transformer {
8185 v ,
8286 read ,
8387 undefined ,
88+ undefined ,
8489 outgoingRecords ,
8590 true
8691 ) ;
@@ -102,6 +107,7 @@ export default class Transformer {
102107 value ,
103108 read ,
104109 undefined ,
110+ undefined ,
105111 outgoingRecords ,
106112 true
107113 ) ;
@@ -207,14 +213,16 @@ export default class Transformer {
207213 * @param {any } value Value of the field.
208214 * @param {Model } model Model class which contains the field.
209215 * @param {Array<String>|undefined } whitelist Contains a list of fields which should always be included.
216+ * @param {Array<GraphQLField>|undefined } schemaFields Contains a list of schema fields which are defined in the model input type for the mutation.
210217 * @returns {boolean }
211218 */
212219 public static shouldIncludeOutgoingField (
213220 forFilter : boolean ,
214221 fieldName : string ,
215222 value : any ,
216223 model : Model ,
217- whitelist ?: Array < String >
224+ whitelist ?: Array < String > ,
225+ schemaFields ?: Array < GraphQLField >
218226 ) : boolean {
219227 // Always add fields on the whitelist.
220228 if ( whitelist && whitelist . includes ( fieldName ) ) return true ;
@@ -225,6 +233,9 @@ export default class Transformer {
225233 // Ignore empty fields
226234 if ( value === null || value === undefined ) return false ;
227235
236+ // Is the field in the mutation type field list, if provided?
237+ if ( schemaFields && ! schemaFields . find ( f => f . name === fieldName ) ) return false ;
238+
228239 // Include all eager save connections
229240 if ( model . getRelations ( ) . has ( fieldName ) ) {
230241 // We never add relations to filters.
0 commit comments