-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get HTTP headers in directives/mutations #262
Comments
@rajzru I'm stuck with the same issue. @mathewbyrne Do you guys have any working examples that we can try with HTTP headers? |
I have tried parsing the HTTP header and body to get header and mutation/query details in HTTP middlewares but I need to copy paste libs code and this is a redundant approach and after #221 it's very easy to implement your auth stack but unable to get headers value now. |
I'll do some docs up tomorrow, graphql is transport agnostic, so we don't expose the http request. Instead you should create some http middleware that extracts what you want (the user?) From the request and adds it to context, which will then be available in your resolvers and directives |
@vektah @Dipen-Dedania I have tried that and working like a charm Authentication
Authorization
Still directive is of struct type so maybe in future we can have an interface implementation there just like resolvers |
@rajzru Thanks! Can you please share a sample code? |
I have implemented this in the following way(pseudo code it might need few changes)
HTTP Middleware
Directive config definition
You can edit the code as per your use case |
I think I am stuck on the same issue but I am not 100% sure. If I am attempting to get a value out of the HTTP header of a GraphQL query, am I to inject this myself into the context? If so, would this be done in the |
For those of you who are in the same boat as me and not quite sure how to implement middleware to retrieve the headers, hopefully, this article helps: https://hackernoon.com/simple-http-middleware-with-go-79a4ad62889b |
I am really new to graphql and we are changing our old REST server to graphQL. I am trying this new custom directive but I am unable to fetch HTTP headers(as we are using multiple headers in old system) in the directive implementation or I am not aware how to that due to lack of documentation.
Expected Behaviour
I should be able to get http headers value in directive/mutation/query
The text was updated successfully, but these errors were encountered: