n1ru4l / envelop

Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
https://envelop.dev
MIT License
787 stars 127 forks source link

Can't respond to errors triggered in plugins #1201

Open ivandotv opened 2 years ago

ivandotv commented 2 years ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug Can't respond to errors triggered in plugins. Errors do bubble up into the server response errors key however there is no way to respond to them (reshape, log etc..)

To Reproduce Consider this: Error thrown in useExtendContext can't be handled anywhere.

  plugins: [
    useExtendContext(() => {
      throw new Error('plugin error')
      return {}
    }),
    useErrorHandler((_errors, _args) => {
    // never triggered
    }),
    useApolloServerErrors({
      debug: true,
      formatter: (err: GraphQLError) => {
        // never triggered
        return err
      }
    }),
  ]
})

Expected behavior Respond to thrown errors before they are sent.

Environment:

Additional context

n1ru4l commented 2 years ago

It is possible to register a handler for errors occurring during context creation in the onPluginInit hook: https://github.com/dotansimha/envelop/blob/2f41de9bba86218bbbde1c614679f222def4c628/packages/core/src/plugins/use-masked-errors.ts#L112-L116

I updated your issue with the reproduction template, can you please provide everything required for helping you (mainly a minimal reproduction on StackBlitz).

YassinEldeeb commented 1 year ago

Hey @ivandotv. It'd be great if you could provide a minimal reproduction example, so that we can help you