Skip to content

Commit

Permalink
clarify error response ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jul 14, 2018
1 parent 58e32bb commit b884239
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions docs/content/reference/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@ func (r Query) DoThings(ctx context.Context) (bool, error) {
graphql.AddErrorf(ctx, "Error %d", 1)

// Pass an existing error out
graphql.AddError(ctx, err)
graphql.AddError(ctx, errors.New("zzzzzt"))

// Or fully customize the error
graphql.AddError(ctx, &graphql.Error{
Message: "A descriptive error message",
Extensions: map[string]interface{}{
"code": "10-4",
}
},
})

// And you can still return an error if you need
return false, errors.New("BOOM! Headshot")
return nil, errors.New("BOOM! Headshot")
}
```

They will be returned in the same order in the response, eg:
```json
{
"data": {
"todo": null
},
"errors": [
{ "message": "Error 1", "path": [ "todo" ] },
{ "message": "zzzzzt", "path": [ "todo" ] },
{ "message": "A descriptive error message", "path": [ "todo" ], "extensions": { "code": "10-4" } },
{ "message": "BOOM! Headshot", "path": [ "todo" ] }
]
}
```

Expand Down

0 comments on commit b884239

Please sign in to comment.