I am fetching a list of documents from the backend using this query:
gql`
query GetUserDocuments($userId: Int!, $filters: DocumentFilter) {
user(userId: $userId) {
id
documents(filters: $filters) {
id
name
}
}
}
`;
The following object is saved in the Apollo cache
User:{"userId":123}
which has 2 nested collections defined inside
documents({"filter":{"archived": false}})
documents({"filter":{"archived": true}})
the apollo cache looks something like this
User:{"userId":123} {
__typename: "User",
userId: 123,
documents({"filter":{"archived": false}}): []
documents({"filter":{"archived": true}}): []
}
On the frontend, I would like to handle this cache so that when I archive a given document, I remove it from the collection documents({"filter":{"archived": false}})
and I want to put it in the collection documents({"filter":{"archived": true}})
. Similarly, when I unarchive a document, I remove it from the archived list and add it to the unarchived list. Is it possible to do this using a cache update? Or do I have to refetch the data, which I would like to avoid?
I tried using cache.modify, however I am getting 2 collections at the same time:
cache.modify({
id: cache.identify({ __typename: "User", userId }),
fields: {
documents: (documents) => {
return documents;
},
},
});