Reputation: 518
I'm developing a real time chat app using graphql and I want to modify fetched data instead of refetch it again - in order to reduce unnecessary network requests.
When my app first init I'm fetching a list of users (that are not the current logged-in user) to display on the sidebar of the app. Each user contains a lastMessage object that represent the last message that he sent or received.
When a user clicks on a user to chat with, another query is submitted in order to get all the messages between the users.
Using subscriptions, I'm updating the messages state when a new message is sent (either by the logged-in user or by the other user).
Now, I want to update the lastMessage object of the related user displayed on the sidebar, but I don't want to refetch all the users again in order to do so, because I have all the updated data in the client, which I received by the subscription event. Instead, I want to update the graphql queried data using js.
Is there a way to do that? Thanks.
Upvotes: 0
Views: 762
Reputation: 50
Apollo cache has a 'modify' method that you can use to set the cache of user's lastMessage.
Upvotes: 2