Skip to content

Commit 57151da

Browse files
committed
Word the warning around the missing parameter
1 parent 5f94793 commit 57151da

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ internal class SchemaClassScanner(
529529
fieldResolver.scanForMatches().forEach { potentialMatch ->
530530
handleFoundType(typeClassMatcher.match(potentialMatch))
531531
}
532-
warnIfArgumentPassedToContext(type, fieldResolver)
532+
warnIfParameterMissing(type, fieldResolver)
533533
}
534534
}
535535

@@ -555,7 +555,7 @@ internal class SchemaClassScanner(
555555
}
556556

557557
// TODO throw a FieldResolverError instead in 15.0.0 (#889)
558-
private fun warnIfArgumentPassedToContext(type: ObjectTypeDefinition, fieldResolver: FieldResolver) {
558+
private fun warnIfParameterMissing(type: ObjectTypeDefinition, fieldResolver: FieldResolver) {
559559
if (fieldResolver !is MethodFieldResolver) {
560560
return
561561
}
@@ -568,9 +568,9 @@ internal class SchemaClassScanner(
568568

569569
val method = fieldResolver.method
570570
log.warn(
571-
"Field '${type.name}.${fieldResolver.field.name}' passes its argument '${argument.name}: ${TypeUtil.simplePrint(argument.type)}' " +
572-
"to the ${parameter.name} parameter of ${method.declaringClass.name}.${method.name}, so the field fails or gets null for " +
573-
"that parameter. Declare one parameter per argument, in order, before the ${parameter.simpleName} parameter."
571+
"Field '${type.name}.${fieldResolver.field.name}' has no parameter for its argument '${argument.name}: " +
572+
"${TypeUtil.simplePrint(argument.type)}' in ${method.declaringClass.name}.${method.name}, so the ${parameter.simpleName} " +
573+
"parameter gets the argument instead. Add a parameter for each argument, in order, before the ${parameter.simpleName} parameter."
574574
)
575575
}
576576
}

‎src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,52 +285,51 @@ class MethodFieldResolverTest {
285285
}
286286

287287
@Test
288-
fun `should warn when an argument is passed to a context parameter`() {
288+
fun `should warn when a resolver method is missing a parameter for an argument`() {
289289
val (_, warnings) = withWarnings {
290290
SchemaParser.newParser()
291291
.schemaString(
292292
"""
293293
type Query {
294-
context(id: ID!, persist: Boolean!): String
295-
graphQLContext(persist: Boolean, id: ID): String
294+
user(id: ID!, active: Boolean!): String
295+
users(active: Boolean, first: Int): String
296296
image: Image
297-
input(input: Input): String
298-
extra(persist: Boolean): String
297+
search(filter: Filter): String
298+
count(active: Boolean): String
299299
}
300300
301301
type Image {
302302
thumbnail(size: Int): String
303303
}
304304
305-
input Input {
306-
value: String
305+
input Filter {
306+
name: String
307307
}
308308
""")
309-
.resolvers(ContextParameterQuery(), ImageResolver())
309+
.resolvers(MissingParameterQuery(), ImageResolver())
310310
.options(SchemaParserOptions.newOptions().contextClass(Map::class).build())
311311
.build()
312312
.makeExecutableSchema()
313313
}
314314

315-
val query = ContextParameterQuery::class.java.name
315+
val query = MissingParameterQuery::class.java.name
316316
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."
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."
325324
))
326325
}
327326

328-
class ContextParameterQuery : GraphQLQueryResolver {
329-
fun context(id: String, context: Map<String, Any>) = "$id $context"
330-
fun graphQLContext(context: GraphQLContext?, id: String?) = "$context $id"
327+
class MissingParameterQuery : GraphQLQueryResolver {
328+
fun user(id: String, context: Map<String, Any>) = "$id $context"
329+
fun users(context: GraphQLContext?, first: Int?) = "$context $first"
331330
fun image() = Image()
332-
fun input(input: Map<String, Any>?) = input.toString()
333-
fun extra(persist: Boolean?, context: Map<String, Any>) = "$persist $context"
331+
fun search(filter: Map<String, Any>?) = filter.toString()
332+
fun count(active: Boolean?, context: Map<String, Any>) = "$active $context"
334333
}
335334

336335
class Image

0 commit comments

Comments
 (0)