apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
807 stars 272 forks source link

Custom FetchError members and formatters #3461

Open xuorig opened 1 year ago

xuorig commented 1 year ago

Our GraphQL errors have a particular format that differs from the router's defaults. (https://netflix.github.io/dgs/error-handling/#the-typederror-interface)

Most of the time, these errors are simply returned from subgraphs. However, in the case of a FetchError, the router itself should format the error in a similar manner.

Currently, the router defines the FetchError enum and also controls how these errors are mapped the the final graphql error, including extensions.

In our subgraph service, we'd like the ability to do two things:

  1. Return other kinds of or custom FetchError
  2. Control how FetchError get converted to a GraphQL error.
BrynCooke commented 1 year ago

@xuorig Is it possible for you to use a rhai script to convert the errors into the format that you'd like?

xuorig commented 1 year ago

@BrynCooke it's possible, and it is our current workaround (RouterService plugin rather than rhai).

The problem is that this requires us to deal with untyped structures and match against String codes. Longer term this would be too brittle to handle.

A translation abstraction between router (Fetch and Planning errors) and graphql errors would be very useful!

o0Ignition0o commented 11 months ago

We've made fairly decent progress, I suspect a PR to open within 2 weeks.

o0Ignition0o commented 11 months ago

I'm going to fix CI and mark https://github.com/apollographql/router/pull/4131 as ready for early review