Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.02k stars 99 forks source link

How can I get response header #326

Closed wayne163 closed 3 months ago

wayne163 commented 3 months ago

Hi there,

I'm new to GraphQL, and has finished this tutorial. Now I want to get value from response header, but find that I can't get resp header from generated.go. I'm not sure whether there is way to get it. If not, I think it's better to add resp header in return of generated code.

benjaminjkraft commented 3 months ago

You can get response headers similarly to setting request headers; see the documentation here. (Instead of looking at req.Header before the request, you'd look at resp.Header after.) Depending what you want to do that may not be super convenient, though -- if you can give more context on your use case it would help evaluate whether there's a reason to add this (or if there's a better way to do what you want -- in general setting response headers in GraphQL isn't a thing most servers tend to do in my experience).