Skip to content

Schema inspection should detect mismatch between optional arguments in GraphQL schema and Kotlin non-nullable method parameters #1220

Open
@Rustavil

Description

@Rustavil

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!"
    }
}

GitHub full project to reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues related to working with datatype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions