absinthe-graphql / absinthe

The GraphQL toolkit for Elixir
http://absinthe-graphql.org
Other
4.29k stars 526 forks source link

Handle Unknown Exceptions, Process Crashes and provide respective errors with GraphQL #1219

Open kasvith opened 1 year ago

kasvith commented 1 year ago

If submitting a bug, please provide the following:

Environment

Expected behavior

Absinthe should provide a formal way to handle unexpected errors, exceptions or process crashes(for example inside DataLoader.KV) and allow customized errors returned to the GraphQL client.

Actual behavior

Currently, when something goes wrong, we get phoenix default ErrorView. This is bad for even development environments. GraphQL server should be able to properly reply with a JSON response when some error occurs.

There are community-based blog posts where that tackle this issue

But these blog posts or methods don't work when a process crashes, for example

I believe this part is crucial for a GraphQL server, I spent hours and days on this issue until I found the above blog posts, but they don't cover the above use cases.

It would be awesome to have some official support to tackle these situations much more swiftly as I believe this is a common problem when working with Absinthe in a production environment

Relevant Schema/Middleware Code

yurtsiv commented 1 year ago

There's also an issue with queries/mutations over WebSockets, where it falls into a reconnection loop. It could be patched on the client (https://github.com/absinthe-graphql/absinthe-socket/issues/57), but returning proper GraphQL errors from the server is a better solution.

kasvith commented 1 year ago

@yurtsiv server should send proper errors.

Nezteb commented 9 months ago

I came to create a similar issue before finding this one, mostly because the docs on the subject ask for contributions: https://hexdocs.pm/absinthe/1.7.6/errors.html 😄

I asked for opinions in the Elixir Slack channel for Absinthe and a few links were shared:

My question to the maintainers: should Absinthe "provide a formal way to handle unexpected errors" as the OP believes? If not, what sort of guidance should live on the docs "errors" page?

cc @maartenvanvliet @bruce since y'all wrote the original requests for assistance 2 and 7 years ago. 😄 screenshot_2024-02-14_at_20 07 14@2x

Regardless of the answer, I'd like to assist!