Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting objects in two-directional "array relationship" cause reference errors - and a question... #380

Open
pkreipke opened this issue Jul 7, 2022 · 2 comments
Assignees
Labels
bug Something isn't working question Further information is requested
Milestone

Comments

@pkreipke
Copy link

pkreipke commented Jul 7, 2022

I am using Hasura + Postgres to host my data models. In those models I have "sources" each of which can be connected from many "sinks". E.g. source_id is a FK in sinks table to an entry in sources. Hasura then represents this as an "array relationship" to a field in sources called assignedSinks.

In memory:

sources: [
{ id: 1, assignedSinks: [ { id: 11, name...} ] },
{ id: 2, assignedSinks: [ { id: 12, name...} ] }
]

sinks: [
   { id: 11, source_id: 1, label...},
   { id: 12, source_id: 2, label...}
]

I've scaffolded my models through mst-gql and loaded the code into my React Native app successfully, am able to query the data using the gen'd queries and that all is mostly fine. I have two concerns:

  1. if I try to clear the data in the client using the generated stores' .clear() functions I get an error telling me that each of the sinks was already deleted earlier.
clearAll() {
  self.sources.clear()
  self.sinks.clear()
}
Error: [mobx-state-tree] You are trying to read or write to an object that is no longer part of a state tree. (Object type: 'Sources, Path upon death: '/sources/11669502-f315-4938-a95e-14ed769a7718', Subpath: 'assignedSinks'

In plain old mobx-state-tree safeReference can protect and cascade deletes so that this doesn't happen but it looks like mst-gql isn't use safeReferences.

2a) FYI I'm clearing the models first because of something related: if I run a mutation against the data that nulls out the FK value between the tables (e.g. set sinks.source_id = null, and return only sinks row, then the corresponding source's assignedUpdates is not updated at once. I think it's because Hasura delays nested updates to related tables. That's a bit too bad, don't know how to solve.

2b) But while testing that problem, I deleted a few sinks from my test data and noticed that when I refreshed my app with data from the server mst-gql's merge() functionality didn't seem to remove sinks that no longer existed on the server. I have no idea why. Perhaps the local cache? Perhaps merge can't detect deletes (how could it)? Ergo I started trying to clear out data first - see 1).

Am I doing some of these things wrong in mst-gql?

I'd be curious for any insights, thanks!

@pkreipke
Copy link
Author

pkreipke commented Jul 7, 2022

ed. renamed from 'targets' to 'sinks'.

@Benz19
Copy link
Collaborator

Benz19 commented Nov 5, 2022

HI @pkreipke Im trying to help @jesse-savary clean up all outstanding issues... I understand this message was send back in July - Do you still have the same questions?

@jesse-savary jesse-savary self-assigned this Nov 6, 2022
@jesse-savary jesse-savary added bug Something isn't working question Further information is requested labels Nov 6, 2022
@jesse-savary jesse-savary added this to the v0.18.0 milestone Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants