Skip to content

Commit

Permalink
Add fields to Errors and export Errors for type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe committed Feb 14, 2023
1 parent 77dcbdb commit 2991e3b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab
}
var out struct {
Data *json.RawMessage
Errors errors
Errors Errors
//Extensions interface{} // Unused.
}
err = json.NewDecoder(resp.Body).Decode(&out)
Expand All @@ -108,20 +108,23 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab
return nil
}

// errors represents the "errors" array in a response from a GraphQL server.
// Errors represents the "errors" array in a response from a GraphQL server.
// If returned via error interface, the slice is expected to contain at least 1 element.
//
// Specification: https://facebook.github.io/graphql/#sec-Errors.
type errors []struct {
// Specification: http://spec.graphql.org/June2018/#sec-Errors
type Errors []struct {
Message string
Locations []struct {
Line int
Column int
}
Path []interface{}
Extensions map[string]interface{}
Type string
}

// Error implements error interface.
func (e errors) Error() string {
func (e Errors) Error() string {
b := strings.Builder{}
l := len(e)
for i, err := range e {
Expand Down

0 comments on commit 2991e3b

Please sign in to comment.