Skip to content

Commit

Permalink
fix an error handling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Feb 11, 2018
1 parent 1da57f5 commit 261b52c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"

"github.com/mitchellh/mapstructure"
"github.com/vektah/gqlgen/neelance/errors"
)

// Client for graphql requests
Expand Down Expand Up @@ -102,8 +103,8 @@ func (p *Client) Post(query string, response interface{}, options ...Option) err
}

respData := struct {
Data interface{} `json:"data"`
Errors json.RawMessage `json:"errors"`
Data interface{} `json:"data"`
Errors []*errors.QueryError `json:"errors"`
}{
Data: response,
}
Expand Down
10 changes: 10 additions & 0 deletions example/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ func TestTodo(t *testing.T) {
require.Equal(t, "t2", resp.B.ID)
})

t.Run("find a missing todo", func(t *testing.T) {
var resp struct {
Todo *struct{ Text string }
}
err := c.Post(`{ todo(id:99) { text } }`, &resp)

require.Error(t, err)
require.Nil(t, resp.Todo)
})

t.Run("select all", func(t *testing.T) {
var resp struct {
Todo struct {
Expand Down
1 change: 1 addition & 0 deletions neelance/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func ErrorWriter(errs []*QueryError) jsonw.Writer {

errObj.Add("locations", locations)
}
res = append(res, errObj)
}

return res
Expand Down

0 comments on commit 261b52c

Please sign in to comment.