question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extensions in ApolloError can only contain code

See original GitHub issue

According 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.

https://github.com/apollographql/apollo-server/blob/6ffec8e4535946289f724451aed8b2ade966cac5/packages/apollo-server-errors/src/index.ts#L35

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
joepuzzocommented, Jun 25, 2019

Ok so i have determined this is due to the enrichError function found here. This is really bad because if you call new 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.

1reaction
trevor-scheercommented, Oct 14, 2019

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 ✅

  1. Extensions can’t be provided via the ApolloError constructor (they are overwritten)
  2. The message property on the 3rd constructor argument overwrites the original message

Uncertain / needs clarification: I see some discussion about name, though I’m unsure how it pertains. I see it being used in enrichError, but I’m not sure how it relates to the original intent of this issue. Possibly a separate issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling - Apollo GraphQL Docs
When Apollo Server formats an error in a response, it sets the code extension to this value if no other code is set....
Read more >
The Apollo error doesn't contain the payload - Stack Overflow
Docs say it allows "arbitrary fields to the error's extensions object to provide additional context to the client" and the code they provide...
Read more >
Top GraphQL Errors and How to fix them
Error handling in GraphQL is different on both server and client side tooling. You no longer are looking at HTTP status codes to...
Read more >
Error handling with Apollo Server | Tomek's blog
code : PERSISTED_QUERY_NOT_SUPPORTED) - also only for persisted queries. All the above errors extend ApolloError class (extensions.code: ...
Read more >
GraphQL error handling to the max with Typescript, codegen ...
Not only have we made our API safer code-wise, but also better from a documentation standpoint: now we can also see which Errors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found