Open
Description
When a 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, as Kotlin expects a value.
Spring GraphQL does not provide warnings during schema inspection for this mismatch, making it difficult to identify the issue during development, especially when migrating huge GraphQL schema to Spring-graphQL project.
Short overview of the problem:
Define a GraphQL schema with an optional argument:
type Query {
greet(name: String!, title: String): String!
}
Kotlin controller with a non-nullable parameter for the optional argument:
@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!"
}
}