@@ -10,6 +10,7 @@ import {
1010 singularize
1111} from "../support/utils" ;
1212import { ConnectionMode } from "../adapters/adapter" ;
13+ import { GraphQLType } from "../support/interfaces" ;
1314
1415/**
1516 * This class provides methods to transform incoming data from GraphQL in to a format Vuex-ORM understands and
@@ -222,6 +223,9 @@ export default class Transformer {
222223 // Ignore empty fields
223224 if ( value === null || value === undefined ) return false ;
224225
226+ // Ignore fields that don't exist in the input type
227+ if ( ! this . inputTypeContainsField ( model , fieldName ) ) return false ;
228+
225229 // Include all eager save connections
226230 if ( model . getRelations ( ) . has ( fieldName ) ) {
227231 // We never add relations to filters.
@@ -239,6 +243,23 @@ export default class Transformer {
239243 return true ;
240244 }
241245
246+ /**
247+ * Tells whether a field is in the input type.
248+ * @param {Model } model
249+ * @param {string } fieldName
250+ */
251+ private static inputTypeContainsField ( model : Model , fieldName : string ) : boolean {
252+ const inputTypeName = `${ model . singularName } Input` ;
253+ const inputType : GraphQLType | null = Context . getInstance ( ) . schema ! . getType (
254+ inputTypeName ,
255+ false
256+ ) ;
257+
258+ if ( inputType === null ) throw new Error ( `Type ${ inputType } doesn't exist.` ) ;
259+
260+ return inputType . inputFields ! . find ( f => f . name === fieldName ) != null ;
261+ }
262+
242263 /**
243264 * Registers a record for recursion detection.
244265 * @param {Map<string, Array<string>> } records Map of IDs.
0 commit comments