mst-gql icon indicating copy to clipboard operation
mst-gql copied to clipboard

Value in store is not updated after mutation

Open krstns opened this issue 3 years ago • 3 comments

According to docs, calling mutateUpdate* methods without passing additional parameters (like in the examples) should automatically update the data in the store without the need of a re-query. I have strange results depending on where I run them.

Local machine:

  • calling mutate and then query with default caching will return the previous value.
  • calling mutate and then query with no-cache will return updated value
  • calling mutate and accessing object by using get will return object with old value

Stackblitz:

  • calling mutate and then query with default caching will return updated value.
  • calling mutate and then query with no-cache will return updated value
  • calling mutate and accessing object by using get will return object with old value

Here's my example: https://stackblitz.com/edit/jasmine-in-angular-ioexpj?file=src%2Flib%2Fdata-manager.service.spec.ts

I would like to understand why the object is not updated in the store, as according to the docs it should be. Also if someone could let me know why i have such a difference between stackblitz and my machine regarding the cached query it would be great.

krstns avatar Mar 02 '22 16:03 krstns

Hey, taking a look into this.

jesse-savary avatar Mar 21 '22 18:03 jesse-savary

I have same issue

ryskin avatar Jun 03 '22 07:06 ryskin

@ryskin Our solution (and I think the preferred official one) is to:

  • create a selector for the update with the updated fields
  • use the optimistic update to apply the update in the store

By using these two we are ok with our app. The update is immediate, when a query fails it's automatically reverted, the state of our store is the one we would expect to have.

Still, it's strange it does not work out of the box.

krstns avatar Jun 13 '22 08:06 krstns