@@ -10,6 +10,7 @@ import {
10
10
singularize
11
11
} from "../support/utils" ;
12
12
import { ConnectionMode } from "../adapters/adapter" ;
13
+ import { GraphQLType } from "../support/interfaces" ;
13
14
14
15
/**
15
16
* 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 {
222
223
// Ignore empty fields
223
224
if ( value === null || value === undefined ) return false ;
224
225
226
+ // Ignore fields that don't exist in the input type
227
+ if ( ! this . inputTypeContainsField ( model , fieldName ) ) return false ;
228
+
225
229
// Include all eager save connections
226
230
if ( model . getRelations ( ) . has ( fieldName ) ) {
227
231
// We never add relations to filters.
@@ -239,6 +243,23 @@ export default class Transformer {
239
243
return true ;
240
244
}
241
245
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
+
242
263
/**
243
264
* Registers a record for recursion detection.
244
265
* @param {Map<string, Array<string>> } records Map of IDs.
0 commit comments