hasura / go-graphql-client

Package graphql provides a GraphQL client implementation.
MIT License
395 stars 91 forks source link

feat: decode extensions from response via BindExtensions option #146

Closed hgiasac closed 2 months ago

hgiasac commented 2 months ago

The response map may also contain an entry with key extensions. To decode this field you need to bind a struct or map pointer. The client will optionally unmarshal the field using json decoder.

var q struct {
    User struct {
        ID   string `graphql:"id"`
        Name string `graphql:"name"`
    }
}

var ext struct {
    ID     int    `json:"id"`
    Domain string `json:"domain"`
}

err := client.Query(context.Background(), &q, map[string]interface{}{}, graphql.BindExtensions(&ext))
if err != nil {
    t.Fatal(err)
}
github-actions[bot] commented 2 months ago

Code Coverage

Package Line Rate Health
github.com/hasura/go-graphql-client 67%
github.com/hasura/go-graphql-client/ident 100%
github.com/hasura/go-graphql-client/pkg/jsonutil 84%
Summary 72% (1412 / 1959)

Minimum allowed line rate is 60%