mst-gql: Model cannot find the store/parent at depth 2
Hi,
I initially created an issue at the mobx-state-tree repo, but found out it was related to mst-gql insted.
There’s a thorough explanation here: https://github.com/mobxjs/mobx-state-tree/issues/1408.
TL;DR: I wasn’t able to get to the root store from within a model in order to call the mst-gql-generated GraphQL query/mutation functions. I was getting a Uncaught Error: [mobx-state-tree] Failed to find the parent of User@/me(id: Guest) at depth 2 error.
After some digging, I fixed it by replacing the getParent(self, 2) call here by getRoot(self).
I don’t know if this is a bug or if it’s related to something I did wrong. If it’s confirmed to be a bug, I’ll gladly prepare a PR, if not, any insights would be greatly appreciated!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 19 (3 by maintainers)
on our app we just have a boolean on the root store for if you are logged in or not. I’m not sure if this would work in your case, but we adjust the UI and calls made based on this flag.
Once a user is logged in we get the ID out of the JWT the
meview on the root store uses that to return the correct user from users.