graphql-spring-boot icon indicating copy to clipboard operation
graphql-spring-boot copied to clipboard

Forwarding of `RequestContext` not working in async mode

Open pelletier197 opened this issue 2 years ago • 5 comments

Describe the bug Many spring framework rely on the RequestContextHolder static class to access the current request attributes. One of them is the Spring-OAuth2 framework that uses it to relay user-token attributes stored in the session to other services in a micro-service architecture.

Only problem being that in async mode, the RequestContextHolder.getRequestAttributes() returns null. I see that something custom was required to do this with the security context, so would something similar be possible for RequestContext ?

To Reproduce Steps to reproduce the behavior:

  1. Enable async mode
  2. Perform any request, and just call RequestContextHolder.getRequestAttributes() from within any resolver. You should see that it's null.
  3. Disable async mode
  4. Do the same thing, and the attributes should be non-null

Expected behavior Expect the request attributes to be forwarded when the resolvers are called. Having the request in the DataFetchingEnvironment is unfortunately not enough for libraries.

pelletier197 avatar Oct 04 '21 13:10 pelletier197