Hello,
I have a query like this: comments(type: All | Upvoted | Downvoted)
and I use type
as a keyArg.
When user opens the page he fetches all the comments and later he can narrow his search. I wonder if it’s possible to somehow prepopulate store of type: Upvoted |Downvoted
with the results from type: All
query. Unfortunately preloadQuery
doesn’t have update
function as mutation do so not sure what’s the best way to achiive that.
I tried to use read
field policy but that gives me Already recomputing error
here is an example of what I tried:
comments: {
keyArgs: ['type'],
merge: mergePaginatedCollections,
read(existing, { cache, args }) {
const variables = args as CommentsQueryQueryVariables;
if (!existing && variables.type !== VoteTypeFilter.All) {
const d = cache.readQuery({
query: CommentsQuery,
variables,
});
return {
...d,
comments: {
...d?.comments,
items: d?.comments.items.filter(
(c) => c.type === variables.type,
),
},
};
}
return existing;
},
},
Thanks in advance for any tips