-
Notifications
You must be signed in to change notification settings - Fork 315
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 use Context? #1138
Comments
Current solution: |
I think you're conflating two different concepts: context propagation and the GraphQL context. Context propagation in Spring for GraphQL and the Context Propagation Library are about propagating context values from one context object to another: thread locals, the GraphQL Context, the Reactor Context. While traditional, "one thread per request", applications use thread locals for such things, this doesn't work as soon as you're opting in for a different execution model. Context propagation helps you to seamlessly use all of those together. The GraphQL Context is a map that applications can use to store any relevant information for fetching data: security authorities, hints, etc. It seems your problem is mostly related to partial data and nullability in the schema? Maybe you can share a small code snippet showing that part of your schema and the relevant |
So I want to populate graphql context (or whatever context, I don't mind if I use an abstraction, maybe it's better for consistency) with errors so that right before returning data I can also populate errors in the response alongside it. I found a good example that's very similar to what I want: https://stackoverflow.com/questions/71795252 I have a paginated endpoint (Connection) and as I generate new items I want to include errors/warnings saying that the list that is getting generated is going off the tracks but I still want to return the items to draw a graph in my UI. So the UI will show the graph and it will also show warnings/errors about it. Let me know if you still want the exact code, it'll take me some time to anonymize it... My current solution (described in the last comment) works fine, I just declare a I don't like that I must forward |
Confused on the documentation. So, the docs talk about using
io.micrometer.context.ThreadLocalAccessor
but doesn't give any full examples, e.g. I don't understand what you mean by "register it manually on startup or by callingio.micrometer.context.ContextRegistry#getInstance()
" - you mean server startup like in on context refresh or do you mean like on request startup, so I have to add some sort of interceptor to deal with it? There's a quick mention of@LocalContextValue
as well asGraphQLContext
that it can be injected into the method signature - that seems like what I actually need, not sure why even mention micrometer stuff?My usecase is that I want to return a partial result: I paginate through items, at some point the items might become bad so I will include both the items and corresponding errors/extensions. If I throw an error, data is null, so I return normally but set context and then in an interceptor I check it and populate the errors/extensions.
The text was updated successfully, but these errors were encountered: