diff --git a/README.md b/README.md index e15cc92..fb5a067 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ For more information, see package [`github.com/shurcooL/githubv4`](https://githu - [Options](#options-1) - [Execute pre-built query](#execute-pre-built-query) - [Get extensions from response](#get-extensions-from-response) + - [Get headers from response](#get-headers-from-response) - [With operation name (deprecated)](#with-operation-name-deprecated) - [Raw bytes response](#raw-bytes-response) - [Multiple mutations with ordered map](#multiple-mutations-with-ordered-map) @@ -753,11 +754,12 @@ type Option interface { client.Query(ctx context.Context, q interface{}, variables map[string]interface{}, options ...Option) error ``` -Currently, there are 3 option types: +Currently, there are 4 option types: - `operation_name` - `operation_directive` - `bind_extensions` +- `bind_response_headers` The operation name option is built-in because it is unique. We can use the option directly with `OperationName`. @@ -882,6 +884,21 @@ if err != nil { fmt.Println("Extensions:", extensions) ``` +### Get headers from response + +Use the `BindResponseHeaders` option to bind headers from the response. + +```go +headers := http.Header{} +err := client.Query(context.TODO(), &q, map[string]any{}, graphql.BindResponseHeaders(&headers)) +if err != nil { + panic(err) +} + +fmt.Println(headers.Get("content-type")) +// application/json +``` + ### With operation name (deprecated) ```Go diff --git a/option.go b/option.go index b3578c0..cfadfc1 100644 --- a/option.go +++ b/option.go @@ -55,7 +55,7 @@ type bindResponseHeadersOption struct { } func (ono bindResponseHeadersOption) Type() OptionType { - return "bind_extensions" + return "bind_response_headers" } // BindExtensionsBindResponseHeaders bind the header response to the pointer diff --git a/subscription_graphql_ws_test.go b/subscription_graphql_ws_test.go index 13dde99..b75fb5e 100644 --- a/subscription_graphql_ws_test.go +++ b/subscription_graphql_ws_test.go @@ -20,16 +20,6 @@ const ( hasuraTestAdminSecret = "hasura" ) -type headerRoundTripper struct { - setHeaders func(req *http.Request) - rt http.RoundTripper -} - -func (h headerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - h.setHeaders(req) - return h.rt.RoundTrip(req) -} - type user_insert_input map[string]interface{} func hasura_setupClients(protocol SubscriptionProtocolType) (*Client, *SubscriptionClient) {