I have 3 different components that use the same graphql query. This example would be GET_USERS
query. This is used when looking for users to message in the messaging respective tab and also when inviting users for actions and tagging them when creating posts.
the problem I'm having and trying to figure out how to handle is that its not always the case that only one is rendered at a time. A user might click the message tab and then go to tag a user in the post tab. Problem: when he comes back to the message tab it now has re-rendered with the state of the query that was called from the tagging.
Any suggestions on how to set up the state with Apollo and the queries in general to avoid this issue. At the end of the day my backend is one "route" or resolve
function for the specific action.
EDIT
For further information. The way I know I could solve it is to use axios request to the graphql endpoint and store the response in local useState
for that component. If I did this for each of the different places in the app that use the information they would remain decoupled and not share the exact same state.
But to be clear I am trying to solve this while using Apollo if possible.
cache-only
fetchPolicy in queries/components you want to not affect 'main source of truth' ? – Bereniceberenson