How can graphQl update its won cache in reaction to data mutations triggered by a different user?

How can graphQl update its won cache in reaction to data mutations triggered by a different user?


0

Here is a scenario:

User A is friends with user B. User C is an admin. When user A queries the list of his friends, the list comes back, and user B is one of its members. This list is cached and the following queries are read from the cache. Now, let’s say the admin deleted this friendship from the database. How will graphql (urql’s graphCache in my case) know about this mutation and update user A’s cache to reflect the new state, which is that user B is no longer a friend?

My initial solution to this situation is to set the cache policy for this request to "network-only" fully bypassing the cache. However, the client will make unnecessary round trips that are only going to return new data when a mutation is executed by the admin C. Throughout all those page refreshes and rerenders of the components the query will be making completely unnecessary round trips.

How do I reconcile a clear need for caching and not return stale data from the cache?

Share
Improve this question

1 Answer
1

Reset to default


0

In GraphQL, the client-side cache can be updated in reaction to data mutations triggered by a different user through a combination of subscription mechanisms and cache management techniques.

Share
Improve this answer

New contributor

Harry Brook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



Leave a Reply

Your email address will not be published. Required fields are marked *