Skip to content

Commit

Permalink
Merge branch 'master' into logging
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer authored Dec 28, 2017
2 parents ec43952 + 8ad1e3f commit a2c9213
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: go
go:
- 1.7.x
- 1.8.x
- master
- 1.9.x

before_install:
- go get github.com/golang/lint/golint
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# graphql [![GoDoc](https://godoc.org/github.com/machinebox/graphql?status.png)](http://godoc.org/github.com/machinebox/graphql) [![Build Status](https://travis-ci.org/machinebox/graphql.svg?branch=master)](https://travis-ci.org/machinebox/graphql)
# graphql [![GoDoc](https://godoc.org/github.com/machinebox/graphql?status.png)](http://godoc.org/github.com/machinebox/graphql) [![Build Status](https://travis-ci.org/machinebox/graphql.svg?branch=master)](https://travis-ci.org/machinebox/graphql) [![Go Report Card](https://goreportcard.com/badge/github.com/machinebox/graphql)](https://goreportcard.com/report/github.com/machinebox/graphql)

Low-level GraphQL client for Go.

Expand Down
17 changes: 10 additions & 7 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error
return errors.Wrap(err, "close writer")
}
c.logf(">> vars:%+v files:%d query:%s", req.vars, len(req.files), req.q)
var graphResponse = struct {
Data interface{}
Errors []graphErr
}{
gr := &graphResponse{
Data: resp,
}

r, err := http.NewRequest(http.MethodPost, c.endpoint, &requestBody)
if err != nil {
return err
Expand All @@ -130,12 +128,12 @@ func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error
return errors.Wrap(err, "reading body")
}
c.logf("<< %s", buf.String())
if err := json.NewDecoder(&buf).Decode(&graphResponse); err != nil {
if err := json.NewDecoder(&buf).Decode(&gr); err != nil {
return errors.Wrap(err, "decoding response")
}
if len(graphResponse.Errors) > 0 {
if len(gr.Errors) > 0 {
// return first error
return graphResponse.Errors[0]
return gr.Errors[0]
}
return nil
}
Expand All @@ -161,6 +159,11 @@ func (e graphErr) Error() string {
return "graphql: " + e.Message
}

type graphResponse struct {
Data interface{}
Errors []graphErr
}

// Request is a GraphQL request.
type Request struct {
q string
Expand Down

0 comments on commit a2c9213

Please sign in to comment.