I have a situation where my application is getting data through an external dataSource(A) over websocket.
On receiving this data, I’m doing pubsub.publish( ) to the client connecting through graphql subscription.
In case the external source(A) goes down , the websocket conn will close, but the websocket conn between client and graphql subscription will still be running.
How can I notify client of this error like we do in queries and disconnect the user from server?
@saurav-bhagat assuming that you’re using the WebSocketLink
from @apollo/client/link/ws
, you can define a callback function when you instantiate your WebSocketLink
instance, that will be triggered on a connection error. E.g.:
import { WebSocketLink } from "@apollo/client/link/ws";
const link = new WebSocketLink({
uri: "ws://localhost:3000/subscriptions",
options: {
reconnect: true,
connectionCallback(error, result) {
// Handle the connection error ...
}
}
});
Hi @hwillson,
Thanks for the response.
If I’m not wrong, this callback with error will be invoked if there is some error in the websocket connection or subscription response between the client and graphql server?
But what I want is to send a error from graphql server when there is a websocket connection issue between my graphql server and external data source?
And also the app should unsubscribe the user from graphql subscription.
How can I achieve this?
Please let me know If I’m missing something in my explaination.