Open dyst5422 opened 6 years ago
The asyncIterator's return function is the intended way of cleaning up server resources, as I understand it. Unfortunately, it's not very reliable: https://github.com/apollographql/graphql-subscriptions/issues/143
This idea seems to be somewhat similar to what @taion did here: https://github.com/apollographql/graphql-subscriptions/pull/147#issuecomment-424861481
Definitely looking to figure out the right way forwards on this issue.
Is there any update with this enhancement?
Currently there is a subscribe and a resolve field on resolvers.
I propose an unsubscribe field as well that can be used to release server resources.
There is currently no way to tell running processes that the subscription is no longer active to release the resources. An example is a memory heavy simulation system that is provisioned on subscribing and needs to be torn down when the client closes the connection.
An implementation would have the server create a stack of unsubscribe functions on the socket connection that it adds to on each subscription call. When the socket it closed, it would call each of those unsubscribe functions.