@@ -10,6 +10,7 @@ import graphql.language.Value
1010import graphql.schema.Coercing
1111import graphql.schema.CoercingParseLiteralException
1212import graphql.schema.CoercingSerializeException
13+ import graphql.schema.DataFetchingEnvironment
1314import graphql.schema.GraphQLScalarType
1415import org.junit.Test
1516import java.lang.reflect.InvocationHandler
@@ -283,6 +284,60 @@ class MethodFieldResolverTest {
283284 ))
284285 }
285286
287+ @Test
288+ fun `should warn when a resolver method is missing a parameter for an argument` () {
289+ val (_, warnings) = withWarnings {
290+ SchemaParser .newParser()
291+ .schemaString(
292+ """
293+ type Query {
294+ user(id: ID!, active: Boolean!): String
295+ users(active: Boolean, first: Int): String
296+ image: Image
297+ search(filter: Filter): String
298+ count(active: Boolean): String
299+ }
300+
301+ type Image {
302+ thumbnail(size: Int): String
303+ }
304+
305+ input Filter {
306+ name: String
307+ }
308+ """ )
309+ .resolvers(MissingParameterQuery (), ImageResolver ())
310+ .options(SchemaParserOptions .newOptions().contextClass(Map ::class ).build())
311+ .build()
312+ .makeExecutableSchema()
313+ }
314+
315+ val query = MissingParameterQuery ::class .java.name
316+ assertEquals(warnings, listOf (
317+ " Field 'Query.user' has no parameter for its argument 'active: Boolean!' in $query .user, so the Map parameter gets the " +
318+ " argument instead. Add a parameter for each argument, in order, before the Map parameter." ,
319+ " Field 'Query.users' has no parameter for its argument 'active: Boolean' in $query .users, so the GraphQLContext parameter " +
320+ " gets the argument instead. Add a parameter for each argument, in order, before the GraphQLContext parameter." ,
321+ " Field 'Image.thumbnail' has no parameter for its argument 'size: Int' in ${ImageResolver ::class .java.name} .thumbnail, so the " +
322+ " DataFetchingEnvironment parameter gets the argument instead. Add a parameter for each argument, in order, before the " +
323+ " DataFetchingEnvironment parameter."
324+ ))
325+ }
326+
327+ class MissingParameterQuery : GraphQLQueryResolver {
328+ fun user (id : String , context : Map <String , Any >) = " $id $context "
329+ fun users (context : GraphQLContext ? , first : Int? ) = " $context $first "
330+ fun image () = Image ()
331+ fun search (filter : Map <String , Any >? ) = filter.toString()
332+ fun count (active : Boolean? , context : Map <String , Any >) = " $active $context "
333+ }
334+
335+ class Image
336+
337+ class ImageResolver : GraphQLResolver <Image > {
338+ fun thumbnail (image : Image , env : DataFetchingEnvironment ? ) = env.toString()
339+ }
340+
286341 sealed class Maybe <out T > {
287342 data class Some <T >(val value : T ) : Maybe<T>()
288343 object None : Maybe<Nothing>()
0 commit comments