Is it possible to handle disconnects in graphQL on server side?

Viewed 263

I'm doing a graphQL subscription and I need to catch the moment when a client disconnects (intentionally or by timeout) and do some work like clean caches and unsubscribe RX subscriptions. Is that possible?

I'm using graphql-spring-boot-starter with graphql-java-tools.

Here is my code:

@Component
public class Subscription implements GraphQLSubscriptionResolver {
  
  @Autowired
  InnerService innerService;

    public Publisher<Score> talkScores(final String title) {
        Observable<Score> observable = Observable.create(e -> {
          innerService.internalSubscription(e);
        });
        ConnectableObservable connectableObservable = observable.share().publish();
        connectableObservable.connect();
        return connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
    }

    public void cleanSubscriptions() {
      innerService.clean()
    }
}

How to run cleanSubscriptions() when a client disconnects?

0 Answers
Related