mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.33k stars 234 forks source link

Use error formatter for subscription GQL errors #967

Closed LewisYearsley closed 1 year ago

LewisYearsley commented 1 year ago

RE: https://github.com/mercurius-js/mercurius/issues/966

Currently, if there are graphql errors returned from a subscription in the standard "errors" property on a response - these do not get the opportunity to be passed through the potentially provided errorFormatter. This means any formatting and any side effects you may have in the error formatter are not run for these cases.

This PR applies the provided error formatter or merely the default error formatter as a fallback.

NOTE:

I'm not 100% convinced on this change as is, my main thing is that in the case of mutation/query, we get to override the status code for the response in addition to the main payload. This doesn't apply to subscriptions and therefore that is thrown away in that case. It will work, but semantically may be slightly weird. Open to feedback and suggestions of course.

mcollina commented 1 year ago

This seems correct.