Extensions in ApolloError can only contain code
See original GitHub issueAccording to the graphql spec.
“GraphQL services may provide an additional entry to errors with key extensions. This entry, if set, must have a map as its value. This entry is reserved for implementors to add additional information to errors however they see fit, and there are no additional restrictions on its contents.”
{
"errors": [
{
"message": "Name for character with ID 1002 could not be fetched.",
"locations": [ { "line": 6, "column": 7 } ],
"path": [ "hero", "heroFriends", 1, "name" ],
"extensions": {
"code": "CAN_NOT_FETCH_BY_ID",
"timestamp": "Fri Feb 9 14:33:09 UTC 2018"
}
}
]
}
“GraphQL services should NOT
provide any additional entries to the error format since they could conflict with additional entries that may be added in future versions of this specification.”
SPEC >>> https://github.com/graphql/graphql-spec/blob/master/spec/Section 7 -- Response.md
But it looks like when constructing an Apollo Error it will only allow you to shove the code into extensions. Why don’t additional properties end up on extensions OR will the constructor allow you to pass extensions.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (2 by maintainers)
Top GitHub Comments
Ok so i have determined this is due to the
enrichError
function found here. This is really bad because if you callnew ApolloError('The message i want shown', 'SOME_CODE', { some_exception_data: 'fasdfadf', message: 'This message will override the constructors message :('} )
Then the message in the exception ( additional properties ) will take over.Hey @joepuzzo, @yuchristina, @SekibOmazic, @Benrozenberg, and other interested parties 👋 Thank you all for opening this issue and providing context and workarounds!
I’ve opened a PR to make sure I’m understanding the issue(s) at hand correctly. It seems that we have multiple issues to address, so I’ve started with a couple test cases for validation from you all. These tests are currently failing as expected. Please feel free to @ me here or comment on the PR with anything that’s incorrect or overlooked.
Confirmed ✅
ApolloError
constructor (they are overwritten)Uncertain / needs clarification: I see some discussion about
name
, though I’m unsure how it pertains. I see it being used inenrichError
, but I’m not sure how it relates to the original intent of this issue. Possibly a separate issue?