You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to connect kotlin, spring for graphql, and the validation feature, but when I add the directive wiring, the exceptions thrown in the service layer are not being displayed correctly.
Config:
@Configuration
class GraphQLConfig {
@Bean
fun runtimeWiringConfigurer(): RuntimeWiringConfigurer {
val validationRules = ValidationRules.newValidationRules()
.onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
.build()
val schemaWiring = ValidationSchemaWiring(validationRules)
return RuntimeWiringConfigurer { builder: RuntimeWiring.Builder ->
builder.directiveWiring(schemaWiring).build()
}
}
}
Controller:
@MutationMapping
fun createCourse(
@Arguments createCourseDto: CreateCourseDto
): CourseDto {
throw RuntimeException("exception from controller")
}
Graphql:
directive @NotBlank(message : String! = "graphql.validation.NotBlank.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
createCourse(
name: String! @NotBlank
): Course
type Course {
id: ID
name: String
}
When I call this endpoint, the result is an empty object, in the background, an exception is being thrown (check the controller snippet above)
Hi @JBO24, I ended up implementing my own version of the ValidationSchemaWiring, using only the onArgument function.
Another alternative I consider was using the spring validator
Describe the bug
I'm trying to connect kotlin, spring for graphql, and the validation feature, but when I add the directive wiring, the exceptions thrown in the service layer are not being displayed correctly.
Config:
Controller:
Graphql:
When I call this endpoint, the result is an empty object, in the background, an exception is being thrown (check the controller snippet above)
But If I remove the directive wiring config:
I do get the exception as usual:
Is it something wrong with the code, or could this be a bug?
The text was updated successfully, but these errors were encountered: