2 years ago
#11150
Greg Moss
Accessing HTTP headers in GraphQL v17
Currently, I am using a custom context object in my GraphQL application. It is built via a class that extends GraphQLServletContextBuilder. In version 17, they have deprecated the use of the context object. Our app is using the custom context to get access to a variable in the HTTP header to make it available to resolvers via the DataFetchingEnvironment variable added to resolver functions.
I cannot seem to find how to replicate get access to HTTP headers in a resolver function outside of using a custom context object. We're using the built in servlet as part of the GraphQL kickstart package. The only way I've seen referenced so far on how to get anything into the new context is by setting the context via the ExecutionInput call. And that call is buried in their servlet.
The example I've seen:
var executionInput = ExecutionInput.newExecutionInput()
.query(query)
.variables(variables)
.graphQLContext(Map.of(CustomContext.class, context));
I don't necessarily need a custom context object (especially since it's eventually going away), I just need to know how to get access to an HTTP header inside a resolver function if a custom context is no longer the way to do it going forward.
kotlin
graphql-java
0 Answers
Your Answer