I couldn't get it with @ RestControllerAdvice
, and I wanted a little more detailed information than @ExceptionHandler
.
val spring_version=2.2.2.RELEASE
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:6.0.0")
implementation("org.springframework.boot:spring-boot-starter:$spring_version")
implementation("org.springframework.boot:spring-boot-starter-web:$spring_version")
It seems good to register Map <String, ExecutionStrategy>
in the bean.
@Configuration
class GraphQLConfig {
@Bean
fun executionStrategies(): Map<String, ExecutionStrategy> {
val customDataFetcherExceptionHandler = CustomDataFetcherExceptionHandler
return mapOf(
"queryExecutionStrategy" to AsyncExecutionStrategy(customDataFetcherExceptionHandler),
"mutationExecutionStrategy" to AsyncSerialExecutionStrategy(customDataFetcherExceptionHandler)
)
}
class CustomDataFetcherExceptionHandler: SimpleDataFetcherExceptionHandler() {
override fun onException(handlerParameters: DataFetcherExceptionHandlerParameters): DataFetcherExceptionHandlerResult {
//Notify me nicely
//If you want lower level information
// handlerParameters.dataFetchingEnvironment.getContext<GraphQLServletContext>().It seems that you can get it with httpServletRequest.
return super.onException(handlerParameters)
}
}
}
I'm still not sure if ʻAsyncExecutionStrategy and ʻAsyncSerialExecutionStrategy
are okay, but for now I can skip the error to slack or something.
Please comment if there is a better way.
Recommended Posts