@@ -172,9 +172,8 @@ export default class QueryBuilder {
172172 const isForeignKey = model . skipField ( key ) ;
173173 const skipFieldDueId = ( key === 'id' || isForeignKey ) && ! allowIdFields ;
174174
175- const schema = Context . getInstance ( ) . schema ! ;
176- const type = schema . getType ( model . singularName + ( filter ? 'Filter' : '' ) ) ;
177- const schemaField = type ? ( filter ? type . inputFields ! : type . fields ! ) . find ( f => f . name === key ) : null ;
175+ let schemaField : GraphQLField | undefined = this . findSchemaFieldForArgument ( key , field , model , filter ) ;
176+
178177 const isConnectionField = schemaField && Schema . getTypeNameOfField ( schemaField ) . endsWith ( 'TypeConnection' ) ;
179178
180179 // Ignore null fields, ids and connections
@@ -253,6 +252,30 @@ export default class QueryBuilder {
253252 }
254253 }
255254
255+ private static findSchemaFieldForArgument (
256+ name : String , field : GraphQLField | null , model : Model , isFilter : boolean
257+ ) : GraphQLField | undefined {
258+
259+ const schema = Context . getInstance ( ) . schema ! ;
260+ let schemaField : GraphQLField | undefined ;
261+
262+ if ( field ) {
263+ schemaField = field . args . find ( f => f . name === name ) ;
264+
265+ if ( ! schemaField ) {
266+ Context . getInstance ( ) . logger . warn ( `Could find the argument with name ${ name } for the mutation/query ${ field . name } ` ) ;
267+ }
268+ } else {
269+ // We try to find the FilterType or at least the Type this query belongs to.
270+ const type = schema . getType ( model . singularName + ( isFilter ? 'Filter' : '' ) ) ;
271+
272+ // Next we try to find the field from the type
273+ schemaField = type ? ( isFilter ? type . inputFields ! : type . fields ! ) . find ( f => f . name === name ) : undefined ;
274+ }
275+
276+ return schemaField ;
277+ }
278+
256279 /**
257280 * Generates the fields for all related models.
258281 *
0 commit comments