@@ -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,61 @@ class MethodFieldResolverTest {
283284 ))
284285 }
285286
287+ @Test
288+ fun `should warn when an argument is passed to a context parameter` () {
289+ val (_, warnings) = withWarnings {
290+ SchemaParser .newParser()
291+ .schemaString(
292+ """
293+ type Query {
294+ context(id: ID!, persist: Boolean!): String
295+ graphQLContext(persist: Boolean, id: ID): String
296+ image: Image
297+ input(input: Input): String
298+ extra(persist: Boolean): String
299+ }
300+
301+ type Image {
302+ thumbnail(size: Int): String
303+ }
304+
305+ input Input {
306+ value: String
307+ }
308+ """ )
309+ .resolvers(ContextParameterQuery (), ImageResolver ())
310+ .options(SchemaParserOptions .newOptions().contextClass(Map ::class ).build())
311+ .build()
312+ .makeExecutableSchema()
313+ }
314+
315+ val query = ContextParameterQuery ::class .java.name
316+ assertEquals(warnings, listOf (
317+ " Field 'Query.context' passes its argument 'persist: Boolean!' to the java.util.Map parameter of $query .context, so the field " +
318+ " fails or gets null for that parameter. Declare one parameter per argument, in order, before the Map parameter." ,
319+ " Field 'Query.graphQLContext' passes its argument 'persist: Boolean' to the graphql.GraphQLContext parameter of " +
320+ " $query .graphQLContext, so the field fails or gets null for that parameter. Declare one parameter per argument, in order, " +
321+ " before the GraphQLContext parameter." ,
322+ " Field 'Image.thumbnail' passes its argument 'size: Int' to the graphql.schema.DataFetchingEnvironment parameter of " +
323+ " ${ImageResolver ::class .java.name} .thumbnail, so the field fails or gets null for that parameter. Declare one parameter per " +
324+ " argument, in order, before the DataFetchingEnvironment parameter."
325+ ))
326+ }
327+
328+ class ContextParameterQuery : GraphQLQueryResolver {
329+ fun context (id : String , context : Map <String , Any >) = " $id $context "
330+ fun graphQLContext (context : GraphQLContext ? , id : String? ) = " $context $id "
331+ fun image () = Image ()
332+ fun input (input : Map <String , Any >? ) = input.toString()
333+ fun extra (persist : Boolean? , context : Map <String , Any >) = " $persist $context "
334+ }
335+
336+ class Image
337+
338+ class ImageResolver : GraphQLResolver <Image > {
339+ fun thumbnail (image : Image , env : DataFetchingEnvironment ? ) = env.toString()
340+ }
341+
286342 sealed class Maybe <out T > {
287343 data class Some <T >(val value : T ) : Maybe<T>()
288344 object None : Maybe<Nothing>()
0 commit comments