ember-graphql / ember-apollo-client

🚀 An ember-cli addon for Apollo Client and GraphQL
MIT License
279 stars 72 forks source link

Update watchQuery results in the next runloop #420

Closed anehx closed 2 years ago

anehx commented 2 years ago

I'm working on a project that uses watch queries intensively and I'm very excited about how good it works! However, I'm constantly running into problems because watch query results are updated "too fast", for example:

I have a component that is only displayed when property foo is true. This property is fetched by a parent component via watchQuery. Now the component has an action that sets this property to false via a mutation and then transitions to another route. Now if we call that action, it will never reach the transition because the component is destroyed.

This issue could be fixed very easily if we update the changes in the cache in the next runloop:

https://github.com/ember-graphql/ember-apollo-client/blob/b1b558d10be2463a77780ce7f88435bd12975e38/addon/services/apollo.js#L108-L112

If we use next instead of run this problem would be fixed.

Is there anything that speaks against this? How does ember-data do this?