apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Change useSubscription to be Suspense compatible

Open c10b10 opened this issue 1 year ago • 1 comments

I'm working on a real-time data heavy application and we'd like to integrate our subscriptions with Suspense.

Due to reasons having to do with uncertainty around race conditions we:

  • don't use the suggested useQuery + subscribeToMore pattern - this is because it's uncertain if there would be lost events between the moment the data is retrieved and useQuery the moment subscription starts
  • instead, we use the useSubscription hook directly and we return distinct cache manipulating events (INSERT, UPDATE, DELETE): we implement a wrapper that displays a loading state until the READY event is pushed. The computation is done with the onData callback.

We'd like to make this Suspense compatible but currently there's no way of capturing the subscription in a Promise. We'd need the be able to call a version of useSubscription in a promise and resolve the promise only when the READY event is detected.

Is anything like that planned or could I maybe do this some other way with the current API?

c10b10 avatar Mar 11 '24 11:03 c10b10