Hello!
I’m using apollo client on React and I have a question.
I have a query fetchTasks that can be filtered by “Panel”
Panel.ADMIN
Panel.HISTORY
Panel.NORMAL
I have a page with 3 panels, each one querying with it’s filter.
My problem is that fetchTasks is stored in the cache as a single element.
I would like to have in my cache something like:
NormalTasks → Tasks filtered by NormalTasks
HistoryTasks → Tasks filtered by HistoryTasks
AdminTasks → Tasks filtered by AdminTasks
A possible solution I found is to stop using relayStylePagination() because I don’t have the args with this.
So i use
fetchTasks: {
merge(
existing = { edges: [], __typename: "" },
incoming,
{ args, cache }
) {
if (args && !args.after) {
return incoming;
}
if (!incoming) return existing;
const newEdges = incoming.edges;
const pageInfo = incoming.pageInfo;
const newTasks = {
__typename: incoming.__typename,
edges: [...existing.edges, ...newEdges],
pageInfo,
};
return newTasks;
},
},
With that, I can can do something like that to get the desired tasks from the cache:
const tasks: FetchTasksQuery | null = client.readQuery({
query: fetchTasksQueryGql,
variables: {
after: null,
data: {
filterBy: Panel.ADMIN,
},
first: 10,
},});
The problem is that with this technic I have to store the after
value in a local state.
So I would prefer to store the Tasks in the cache based on the page
argument.
Is it possible ? Thank you