Skip to content

Commit

Permalink
Add GraphQL error path (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpulpeiro authored Jan 15, 2024
1 parent 48aa45c commit c8c6617
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ type Error struct {
Line int `json:"line"`
Column int `json:"column"`
} `json:"locations"`
Path []interface{} `json:"path"`
}

// Error implements error interface.
func (e Error) Error() string {
return fmt.Sprintf("Message: %s, Locations: %+v, Extensions: %+v", e.Message, e.Locations, e.Extensions)
return fmt.Sprintf("Message: %s, Locations: %+v, Extensions: %+v, Path: %+v", e.Message, e.Locations, e.Extensions, e.Path)
}

// Error implements error interface.
Expand Down
8 changes: 4 additions & 4 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestClient_Query_partialDataWithErrorResponse(t *testing.T) {
if err == nil {
t.Fatal("got error: nil, want: non-nil")
}
if got, want := err.Error(), "Message: Could not resolve to a node with the global id of 'NotExist', Locations: [{Line:10 Column:4}], Extensions: map[]"; got != want {
if got, want := err.Error(), "Message: Could not resolve to a node with the global id of 'NotExist', Locations: [{Line:10 Column:4}], Extensions: map[], Path: [node2]"; got != want {
t.Errorf("got error: %v, want: %v", got, want)
}

Expand Down Expand Up @@ -110,7 +110,7 @@ func TestClient_Query_partialDataRawQueryWithErrorResponse(t *testing.T) {
if err == nil {
t.Fatal("got error: nil, want: non-nil\n")
}
if got, want := err.Error(), "Message: Could not resolve to a node with the global id of 'NotExist', Locations: [{Line:10 Column:4}], Extensions: map[]"; got != want {
if got, want := err.Error(), "Message: Could not resolve to a node with the global id of 'NotExist', Locations: [{Line:10 Column:4}], Extensions: map[], Path: [node2]"; got != want {
t.Errorf("got error: %v, want: %v\n", got, want)
}
if q.Node1 == nil || string(q.Node1) != `{"id":"MDEyOklzc3VlQ29tbWVudDE2OTQwNzk0Ng=="}` {
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestClient_Query_noDataWithErrorResponse(t *testing.T) {
if err == nil {
t.Fatal("got error: nil, want: non-nil")
}
if got, want := err.Error(), "Message: Field 'user' is missing required arguments: login, Locations: [{Line:7 Column:3}], Extensions: map[]"; got != want {
if got, want := err.Error(), "Message: Field 'user' is missing required arguments: login, Locations: [{Line:7 Column:3}], Extensions: map[], Path: []"; got != want {
t.Errorf("got error: %v, want: %v", got, want)
}
if q.User.Name != "" {
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestClient_Query_errorStatusCode(t *testing.T) {
if err == nil {
t.Fatal("got error: nil, want: non-nil")
}
if got, want := err.Error(), `Message: 500 Internal Server Error; body: "important message\n", Locations: [], Extensions: map[code:request_error]`; got != want {
if got, want := err.Error(), `Message: 500 Internal Server Error; body: "important message\n", Locations: [], Extensions: map[code:request_error], Path: []`; got != want {
t.Errorf("got error: %v, want: %v", got, want)
}
if q.User.Name != "" {
Expand Down

0 comments on commit c8c6617

Please sign in to comment.