Quick tip if you want to read the HTTP headers from the incoming GraphQL request in .NET Core using HotChocolate.
There are 2 ways I found that can be used to achieve this:
- Inject the IHttpContextAccessor in your resolvers.
- Create a custom Query Interceptor and set the context data
First one is rather obvious but let’s see an example on how to take the second approach:
In your resolvers you can now access the context property through the ContextData directly or by injecting it: