I am using spring-boot-graphql-starter
in my project. How can I add this interceptor to the graphql queries? This is how I configure the interceptor. However the context value is not filled in the controller. I am using Webflux.
class RequestHeaderInterceptor : WebGraphQlInterceptor {
private val ccc = "zzz"
override fun intercept(request: WebGraphQlRequest, chain: WebGraphQlInterceptor.Chain): Mono<WebGraphQlResponse> {
val value = request.headers.getFirst(ccc)
request.configureExecutionInput { _, builder ->
builder.graphQLContext(mapOf("token" to value)).build()
}
return chain.next(request)
}
}
You need to declare it as a bean. From the WebGraphQlInterceptor documentation:
GraphQlWebFluxAutoConfiguration class is responsible for registering all the interceptor beans.