Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to provide context to response in WebGraphQlInterceptor? #1063

Open
hameno opened this issue Oct 4, 2024 · 3 comments
Open

How to provide context to response in WebGraphQlInterceptor? #1063

hameno opened this issue Oct 4, 2024 · 3 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@hameno
Copy link

hameno commented Oct 4, 2024

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"))
        }
    }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 4, 2024
@bclozel
Copy link
Member

bclozel commented Oct 4, 2024

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?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Oct 4, 2024
@hameno
Copy link
Author

hameno commented Oct 4, 2024

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 4, 2024
@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
@bclozel bclozel added status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Oct 9, 2024
@bclozel
Copy link
Member

bclozel commented Oct 18, 2024

After discussing this with @rstoyanchev , I have decided to remove my previous comment as it was misleading. Manually setting a ThreadLocal from a controller and expecting the value to be accessible in a filter would not work reliably and would create lifecycle issues.

I'm reopening this issue to discuss this more thoroughly and consider different options.

First, we had several questions about tenant ids and how to propagate that information. But usually this happens "top to bottom", as the information is extracted at the protocol at the same time as authentication is performed. In that mode, you can use context propagation and the graphql context. Could you explain things a bit more here? I would really like to better understand where this tenant information is coming from and how can you rely on that information being present if it depends on the query sent by the client. Maybe you could show us some code snippets and explain in details this requirement for your application.

Now propagating an information "bottom to top" is not straightforward and basically calls for some type of mutable map that any data fetcher can put information into. We could use HTTP request attributes for that, although this information might be not accessible from the interceptor contract we're providing now. This information is probably not confidential and might be available anyway in the execution result, which is available. You could even consider putting it in the extensions response map.

Thanks!

@bclozel bclozel reopened this Oct 18, 2024
@bclozel bclozel added status: waiting-for-triage An issue we've not yet triaged and removed status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants