jeddeloh / rescript-apollo-client

ReScript bindings for the Apollo Client ecosystem
MIT License
127 stars 18 forks source link

Subscription resends the same response #109

Closed Pet3ris closed 2 years ago

Pet3ris commented 3 years ago

Hi There,

I'm using the hooks API for subscriptions in the following way:

let subscription = Queries.TraceSubscription.use({
    < variables here >
  },
  ~skip,
  ~fetchPolicy=NoCache
)

Then when I'm checking for changes, multiple updates occur with the same value:

React.useEffect1(() => {
  Js.log(subscription)
  // getting multiple "updates" with the same subscription value
}, [subscription])

Is this intended behavior?

jeddeloh commented 3 years ago

The subscription result is memoized specifically to avoid this. If you're getting different objects on each render, I suspect this is an issue with Apollo. Can you confirm the behavior with vanilla JS? A workaround in the meantime is perhaps to watch specific properties of the subscription result rather than the whole object.

Pet3ris commented 3 years ago

Thanks @jeddeloh, one thing I'm trying now is to add an _id field to each object that is being returned since there was a warning from apollo that recommends it.

Will update here once I see if that fixes it.

Pet3ris commented 3 years ago

Unfortunately, id alone didn't fix the issue. I ended up following your suggestion and added a manual if statement to check if the id has changed from request to request.

jeddeloh commented 3 years ago

@Pet3ris, shall we close this or do you still plan to confirm the behavior in vanilla JS Apollo client?

Pet3ris commented 3 years ago

Feel free to close - I’ve went with the work around! Thanks for checking.