-
Hi, Anyways, I wonder what the best way to refresh related entities in lists is after a mutation is. This is something that happens all the time for my app as all the entities are interrelated. People have birth places, companies have headquarter places, publishers have publishing places books have articles printed in them and so on and I want to display this connection of things and their related things at both ends of the various relationships. A person has the birth place listed and a place will have a list of all people that are born at it. This can be queried because in my GraphQL schema it is possible to ask the following (and similar queries): Person: {
person(id: 1) {
id
birthPlace {
id
}
}
} Place: {
place(id: 4) {
id
peopleByBirthPlaceId {
nodes {
id
}
}
}
} As you can see the data of people born at a place is a list so entities are not automatically added to the list of a place if it is added as a birth place for a new person and it is not automatically removed if the birth place is changed to something else. In Apollo I just created a function that updated the cache after each mutation by having a look at the cache before the mutation and removing the things from the lists that they are not part of after the mutation and adding them to the lists that they will be part of after the mutation. I have no idea if this was the proper way to go (probably not) but it worked. So, what would be the best way to keep this kinds of relationships up-to-date? Also (a related question) is it possible to get the state of a mutated entity before the mutation in the cache update handler? Thank you for your help, I like your client very much so far! Daniel |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi again, Thanks again, |
Beta Was this translation helpful? Give feedback.
Hi again,
to specify the last part of my "related" question: during an after-mutation-update, is it possible to get the state of the mutated field before the mutation to do some updated on the cache (like the relationships mentioned above)? It seems possible to use the
cache.inspectFields("Query")
method go through the whole state and to find things that need updating but all this data is often already known because it follows directly from the state changes of the field during mutation, before and after the change.Thanks again,
Daniel