graphql-request icon indicating copy to clipboard operation
graphql-request copied to clipboard

GraphQLWebSocketClient should have onError and onClose events

Open denniske opened this issue 2 years ago • 0 comments

Hi, I think the GraphQLWebSocketClient should have onError and onClose events so that somebody using that class can handle the error and reconnect later.

https://github.com/prisma-labs/graphql-request/blob/master/src/graphql-ws.ts

    socket.onclose = (e) => {
      this.socketState.acknowledged = false
      this.socketState.subscriptions = {}
    }

    socket.onerror = (e) => {
      console.error(e)
    }

I had the problem that the graphql server went down and my graphql request client did not call complete or error

{
    next: ({ matchStartedSub }) => {
        ...
    },
    complete: () => {
        resolve();
    },
    error(errorValue: ClientError) {
        reject(errorValue);
    },
})

denniske avatar Sep 30 '22 12:09 denniske