I'm implementing a pretty advanced table (using React-Table) for a large, complex set of data. I started by following Apollo's guide implementing offset-based pagination, I got sorting to work as well. What I'm stuck at is combining that with server-side filtering.
My definition of InMemoryCache looks like this - I'm querying a field Targets:
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
Targets: {
...offsetLimitPagination(),
read(existing, { args }): any {
if (args && args.limit !== undefined && args.offset !== undefined) {
return existing && existing.slice(args.offset, args.offset + args.limit);
}
},
},
},
},
},
});
which is pretty much the outcome for what the guide told me to do for Pagination. My component queries backend:
const { networkStatus, error, data, fetchMore, refetch } = useQuery<GetTargetsQuery, GetTargetsQueryVariables>(GET_TARGETS, {
...
notifyOnNetworkStatusChange: true,
variables: {
limit: tableState.pageSize,
offset: tableState.pageNumber * tableState.pageSize,
orderBy: tableState.orderBy,
where: {
_and: [initialFilters, queryFilters],
},
},
});
The issue is, when I'm modifying the queryFilters and data gets refetched, I'm seeing correct data in my Network Tab in browser, but my component still reads the old data from the cache. It seems like the offsetLimitPagination hook is not exactly crafted for incorporating filtering(?).
I can't use the React-Table's built-in filtering, as it only operates on the data that has been queried (which in my case is part of the entire set). How do I modify my InMemoryCache to overwrite the data in cache if there are new filters set? Or is there a better way to tackle this or better question to ask to get this done?