awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
916 stars 265 forks source link

useSubscription does not conform to Apollo #759

Open objectiveSee opened 8 months ago

objectiveSee commented 8 months ago

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 :/ 
      }
    }
  );
Bloodyaugust commented 7 months ago

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.

objectiveSee commented 7 months ago

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. 🧐