If the GraphQL schema defines an argument as optional (nullable), but the corresponding Kotlin controller method parameter is required (non-nullable), a mismatch occurs. This can lead to runtime errors if the client omits the argument, since Kotlin expects a value. Spring GraphQL does not warn about this mismatch during inspection, so it is important to ensure that the nullability in the schema matches the Kotlin method signature.
If the GraphQL scheme is
type Query {
greet(name: String!, title: String): String!
}
and the Kotlin controller is defined as:
@Controller
class QueryGreetController {
@QueryMapping
fun greet(
@Argument name: String,
@Argument title: String, // Intentionally non-nullable to demonstrate GraphQL optional argument problem
): String = when {
title.isNotBlank() -> "Hello, $title $name!"
else -> "Hello, $name!"
}
}
then the GraphQL schema inspection will not report any issues
GraphQL schema inspection:
Unmapped fields: {}
Unmapped registrations: {}
Unmapped arguments: {}
Skipped types: []
Greeting GraphQL query Curl example:
curl -X POST -H "Content-Type: application/json" -d '{ "query": "{ greet(name: \"World\") }" }' http://localhost:8080/graphql