mobxjs / mst-gql

Bindings for mobx-state-tree and GraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Value in store is not updated after mutation

krstns opened this issue · 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.

Hey, taking a look into this.

I have same issue

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