micronaut-projects / micronaut-graphql

A repository for Micronaut and GraphQL integrations
Apache License 2.0
81 stars 43 forks source link

How to get HTTP request headers? #156

Open tuanlt2 opened 3 years ago

tuanlt2 commented 3 years ago

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?

jamesdh commented 3 years ago

@tuanlt2 take a look at the GraphQLExecutionInputCustomizer interface.

donbeave commented 3 years ago

@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