aws-mobile-appsync-sdk-js icon indicating copy to clipboard operation
aws-mobile-appsync-sdk-js copied to clipboard

useSubscription does not conform to Apollo

Open objectiveSee opened this issue 1 year ago • 2 comments

The useSubscription hook using the AppSync link does not work correctly. Specifically, it does not implement the onComplete event which is defined by Apollo documentation. You can reproduce this by simply adding an onComplete handler to any subscription. This is important because there is no other way know when the subscription has been established. It would be nice to send this event.

I can try to make these changes if somebody could point me in the correct direction in the codebase.

Example:


  const { data, loading, error } = useSubscription<TData, TVariables>(
    subscription,
    {
      variables,
      onError,
      onComplete: () => {
        console.log('😵😵😵😵😵😵😵😵😵'); // <---- this never gets called :/ 
      }
    }
  );

objectiveSee avatar Nov 02 '23 22:11 objectiveSee

This issue was a major pain to find, after digging through so much documentation on the Apollo side (and the dearth of docs for this project). I need to know when it's okay to send mutations when my logic depends on receiving the update from this subscription. To do that, I need onComplete. In the meantime, I'm going to have to make my mutation idempotent and re-send it until I see a message come back.

Bloodyaugust avatar Nov 15 '23 23:11 Bloodyaugust

That sounds like a very similar problem. I also noticed that the loading property doesn't really tell us anything in this scenario. It would be great to hear from one of the Amazon engineers who is supporting this project. 🧐

objectiveSee avatar Nov 19 '23 23:11 objectiveSee