Reputation: 31
We are using graphql-subscription in our application in this manner:
When deletion event is arriving into server:
pubsub.publish('onDeleteItem', {onDeleteItem: [msg.payload.ItemId]});
Resolvers:
Subscription: { onDeleteItem: { subscribe: () => pubsub.asyncIterator('onDeleteItem'), }, },
Subscribing to it from our client side:
const onDeleteItemSubscription = gql
subscription onDeleteItem {
onDeleteItem
}
getItemsList () {
queryRef.subscribeToMore({
document: onDeleteItemSubscription ,
updateQuery(prev: { itemList: AssetList }, {subscriptionData: {data}}) {
if (!data) {
return prev;
} else {
const deletedItems = (data as any).onDeleteItem;
return {
itemList {... *### //return filtered list*
}
}
}
}
};
The problem is that sometimes the subscription is working fine and the deleted item is filtered as expected, but very often it just not working at all. There are no error logs. When I debug it, I can see that the problem is that the client is not notified by pubsub.publish().
The problem is occurring with all our subscriptions and this is only one example of them.
What could be the problem? Thanks.
Upvotes: 2
Views: 2067
Reputation: 31
My issue was open subscription that we left open when we closed the component. In some point the server just couldn't manage all the subscriptions.
private subscriptions = new Subscription();
...
this.subscriptions.add( <some new subscription> )
...
// when the component destroyed
this.subscriptions.unsubscribe();
Upvotes: 1