micronaut-graphql icon indicating copy to clipboard operation
micronaut-graphql copied to clipboard

How to get HTTP request headers?

Open tuanlt2 opened this issue 4 years ago • 2 comments

I am using Micronaut GraphQL with Kickstart tool (https://github.com/graphql-java-kickstart/graphql-java-tools). How can I get HTTP request headers in GraphQL resolvers?

tuanlt2 avatar Jan 20 '21 10:01 tuanlt2

@tuanlt2 take a look at the GraphQLExecutionInputCustomizer interface.

jamesdh avatar Feb 03 '21 15:02 jamesdh

@tuanlt2 please check jwt-security example: https://github.com/micronaut-projects/micronaut-graphql/tree/master/examples/jwt-security.

It uses custom GraphQLExecutionInputCustomizer implementation: https://github.com/micronaut-projects/micronaut-graphql/blob/bb9004086874f450e7f7502a3c16107c0346b7ae/examples/jwt-security/src/main/java/example/graphql/RequestResponseCustomizer.java

And after that inside the resolver, you can get the request object from the context: https://github.com/micronaut-projects/micronaut-graphql/blob/766cccb3b5f70d0ba0f6728014146138151f621c/examples/jwt-security/src/main/java/example/graphql/LoginDataFetcher.java#L86

donbeave avatar May 27 '21 20:05 donbeave