apollographql / subscriptions-transport-ws

:arrows_clockwise: A WebSocket client + server for GraphQL subscriptions
https://www.npmjs.com/package/subscriptions-transport-ws
MIT License
1.52k stars 342 forks source link

Subscription unsubscribing when getting a graphQLError #864

Closed bauwaerter closed 3 years ago

bauwaerter commented 3 years ago

Subscription unsubscribes when it gets a graphQL error and it never resubscribes.

Packages:

"dependencies": {
    "@apollo/client": "^3.3.14",
    "apollo-link-timeout": "^3.0.0",
    "graphql": "^15.5.0",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
    "react-router": "^5.2.0",
    "react-router-dom": "^5.2.0",
    "subscriptions-transport-ws": "^0.9.18",
  },

Intended Outcome:

The subscription should stay subscribed when it gets graphQL errors.

Actual Outcome:

Screen Shot 2021-04-08 at 6 12 11 PM Screen Shot 2021-04-08 at 6 26 21 PM

Steps to reproduce:

export const subscriptionLink = new WebSocketLink({
  uri: `${wsScheme}://${graphQLHost}/graphql`,
  options: {
    reconnect: true,
    lazy: true,
  },
})
export const TestComponent: React.FC = () => {
  const { data, error, loading } = useSubscription(TestDocument, { shouldResubscribe: true })
  return <div />
}

Setup your subscription and throw a graphQL error from the server.

I'm not sure if this is the intended behavior, but I don't see a way I can resubscribe. Once the stop command is sent it kills that subscription and it never starts back up again.

bauwaerter commented 3 years ago

After further investigation this issue looks like it has something to do with how apollo client is dealing with subscription errors.