Skip to content

Commit c8c6617

Browse files
authored
Add GraphQL error path (#121)
1 parent 48aa45c commit c8c6617

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

graphql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,12 @@ type Error struct {
332332
Line int `json:"line"`
333333
Column int `json:"column"`
334334
} `json:"locations"`
335+
Path []interface{} `json:"path"`
335336
}
336337

337338
// Error implements error interface.
338339
func (e Error) Error() string {
339-
return fmt.Sprintf("Message: %s, Locations: %+v, Extensions: %+v", e.Message, e.Locations, e.Extensions)
340+
return fmt.Sprintf("Message: %s, Locations: %+v, Extensions: %+v, Path: %+v", e.Message, e.Locations, e.Extensions, e.Path)
340341
}
341342

342343
// Error implements error interface.

graphql_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestClient_Query_partialDataWithErrorResponse(t *testing.T) {
6060
if err == nil {
6161
t.Fatal("got error: nil, want: non-nil")
6262
}
63-
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 {
63+
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 {
6464
t.Errorf("got error: %v, want: %v", got, want)
6565
}
6666

@@ -110,7 +110,7 @@ func TestClient_Query_partialDataRawQueryWithErrorResponse(t *testing.T) {
110110
if err == nil {
111111
t.Fatal("got error: nil, want: non-nil\n")
112112
}
113-
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 {
113+
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 {
114114
t.Errorf("got error: %v, want: %v\n", got, want)
115115
}
116116
if q.Node1 == nil || string(q.Node1) != `{"id":"MDEyOklzc3VlQ29tbWVudDE2OTQwNzk0Ng=="}` {
@@ -165,7 +165,7 @@ func TestClient_Query_noDataWithErrorResponse(t *testing.T) {
165165
if err == nil {
166166
t.Fatal("got error: nil, want: non-nil")
167167
}
168-
if got, want := err.Error(), "Message: Field 'user' is missing required arguments: login, Locations: [{Line:7 Column:3}], Extensions: map[]"; got != want {
168+
if got, want := err.Error(), "Message: Field 'user' is missing required arguments: login, Locations: [{Line:7 Column:3}], Extensions: map[], Path: []"; got != want {
169169
t.Errorf("got error: %v, want: %v", got, want)
170170
}
171171
if q.User.Name != "" {
@@ -215,7 +215,7 @@ func TestClient_Query_errorStatusCode(t *testing.T) {
215215
if err == nil {
216216
t.Fatal("got error: nil, want: non-nil")
217217
}
218-
if got, want := err.Error(), `Message: 500 Internal Server Error; body: "important message\n", Locations: [], Extensions: map[code:request_error]`; got != want {
218+
if got, want := err.Error(), `Message: 500 Internal Server Error; body: "important message\n", Locations: [], Extensions: map[code:request_error], Path: []`; got != want {
219219
t.Errorf("got error: %v, want: %v", got, want)
220220
}
221221
if q.User.Name != "" {

0 commit comments

Comments
 (0)