Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Rustavil opened this issue May 27, 2025 · 1 comment
Labels
in: data Issues related to working with data type: enhancement A general enhancement
Milestone

Comments

@Rustavil
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2025
@bclozel bclozel added type: enhancement A general enhancement in: data Issues related to working with data and removed status: waiting-for-triage An issue we've not yet triaged labels May 27, 2025
@bclozel bclozel added this to the 2.0.x milestone May 27, 2025
@bclozel
Copy link
Member

bclozel commented May 27, 2025

Thanks for raising this.
We have a broader nullness theme going on in the Spring portfolio. We should leverage the new Nullness API and work on this for the next 2.0 major version.

@rstoyanchev rstoyanchev changed the title Mismatch between GraphQL schema optional arguments and Kotlin non-nullable parameters Schema inspection should detect mismatch between optional arguments in GraphQL schema and Kotlin non-nullable method parameters May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues related to working with data type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants