Is your feature request related to a problem? Please describe.
On the Kotlin JVM platform, without the @Valid annotation, we can only perform validation manually.
@Controller
class ClientAddressMutationResolver() {
@MutationMapping
fun createAddress(
@Argument input: AddressInput,
): Address {
if (input.detailAddress.length < 5 || input.detailAddress.length > 200) {
throw Exception("...")
}
}
}
AddressInput is a generated class, such as:
data class AddressInput(
val detailAddress: kotlin.String,
)
Describe the solution you'd like
If AddressInput could be generated with the jakarta.validation.constraints.Size annotation, validation could be automated.
@MutationMapping
fun createAddress(
- @Argument input: AddressInput,
+ @Argument @Valid input: AddressInput,
): Address {
- if (input.detailAddress.length < 5 || input.detailAddress.length > 200) {
- throw Exception("...")
- }
}
Generate AddressInputas shown below:
data class AddressInput(
+ @field:Size(min = 5, max = 200, message = "Detailed address length must be 5-200 characters")
val detailAddress: kotlin.String,
}
And include a custom directive in the GraphQL schema definition:
directive @size(min: Int, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
input AddressInput {
detailAddress: String!
@size(min: 5, max: 200, message: "Detailed address length must be 5-200 characters")
}
Describe alternatives you've considered
Additional context
Is your feature request related to a problem? Please describe.
On the Kotlin JVM platform, without the
@Validannotation, we can only perform validation manually.AddressInputis a generated class, such as:Describe the solution you'd like
If
AddressInputcould be generated with thejakarta.validation.constraints.Sizeannotation, validation could be automated.Generate AddressInputas shown below:
data class AddressInput( + @field:Size(min = 5, max = 200, message = "Detailed address length must be 5-200 characters") val detailAddress: kotlin.String, }And include a custom directive in the GraphQL schema definition:
Describe alternatives you've considered
Additional context