mercurius-js / mercurius

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

[Question] How would you send properly send error for GQL Subcriptions #1104

Open Moonnz opened 3 months ago

Moonnz commented 3 months ago

Hello :)

I've been using Mercurius with NestJS without any issues until now. However, as I'm implementing a subscription, I'm finding it challenging to properly send errors through the subscription WebSocket in accordance with the graphql-ws protocol.

I haven't been able to find any resources on this within the NestJS ecosystem, and it seems there isn't much available within the Mercurius ecosystem either.

Has anyone here managed to handle this or encountered something similar? Any relevant insights would be greatly appreciated!

Moonnz commented 3 months ago

I will create a real issue here, but apparently it's caused by thoose lines of code in the subscription-connection.js file :

case this.protocolMessageTypes.GQL_START: {
  if (this.isReady) {
    this.handleGQLStart(data).catch((e) => {
      this.sendMessage(
        this.protocolMessageTypes.GQL_ERROR,
        id,
        e.message
      )
    })
  }

The graphql-ws protocol said the payload should be an Array of GraphqlError

Moonnz commented 3 months ago

1105