I´m semi new to using Apollo client, I can write queries and handle the response data, but I am new to manipulating the cached data.
I make a req to my DB and get an object, this is then stored to the cache as i understand it, now, within this object there are several fields that i might want to edit, such as a title, a description, coordinates and more these fields are used in a form to display current values and to be able to edit them and then send the form object as a mutation.
My thought is that only when i have changed all the fields that needed to be changed should i send the mutation to the server to keep the DB queries to a minimum, is that correct or am i fundamentally misunderstanding the concept?
After reading the docs i understand there are 2 ways of directly manipulating the cached object. My question is should i use writeQuery or WriteFragment or should i just use mutation directly?
The standard approach is to keep the values in local state while editing them (such as react’s useState), then using a mutation when you want to save. Usually you want your cache data to match your server data as closely as possible.
If you want your mutations to update the cache ASAP without waiting for the server to respond, check out Optimistic Mutation Results