Skip to content

Commit

Permalink
Merge pull request #5 from cli/update-errors
Browse files Browse the repository at this point in the history
Add fields to Errors and export Errors for type assertion
  • Loading branch information
samcoe authored Feb 15, 2023
2 parents 77dcbdb + 2991e3b commit 0c91277
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 0c91277

Please sign in to comment.