spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.52k stars 300 forks source link

How to provide context to response in WebGraphQlInterceptor? #1063

Open hameno opened 3 days ago

hameno commented 3 days ago

We need to access some contextual data about the executed GraphQL query in a HttpFilter. I tried to make use of Context Propagation using a ThreadLocal but it does not seem to be written to (only read).

What am I missing?

Example:

WebGraphQlInterceptor { request, chain ->
        chain.next(request).flatMap { response -> 
            Mono.just(response).contextWrite(Context.of("TEST", "value from response"))
        }
    }
bclozel commented 3 days ago

I'm not sure I entirely understand the use case here.

Where does the value come from and what is this value representing? Where this value should be read? Are you expecting this value to be present in the reactor context, graphql context, somewhere else?

hameno commented 3 days ago

I have a request metering middleware that uses a HttpFilter to perform its task. I need to enrich the data with tenant information that gets calculated during the GraphQL execution. I want to make this tenant data available to the HttpFilter