Skip to content

Commit

Permalink
fix lint and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Feb 14, 2025
1 parent 89a6861 commit 03705bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions subscription_graphql_ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 03705bd

Please sign in to comment.