Hey @jerelmiller!
A runnable example would be difficult, unfortunately. Extracting the cache, it does appear that each individual item is cached under different keys:
Here’s what the merge function gets when the (React Native) screen first queries against the active filter:
LOG -----------args {"input": {"category": "ACTIVE", "limit": 8, "offset": 0}}
LOG -----------existing undefined
LOG -----------incoming [{"__ref": "GroupOffer:fa7a5617-0bc6-46fd-bef3-395661538c44"}, {"__ref": "GroupOffer:f73fb306-0250-4805-b1d1-890d3c6de960"}, {"__ref": "GroupOffer:96ef3c51-aa02-4118-aa4c-18fa754ad122"}, {"__ref": "GroupOffer:372cc59c-8a53-456a-9e93-beb3017b4f80"}, {"__ref": "GroupOffer:fc1be3a5-baa9-4fff-a48b-d637130e5008"}]
Which corresponds to the cache values here:
GroupOffer:96ef3c51-aa02-4118-aa4c-18fa754ad122: { ...offerDetails }
GroupOffer:372cc59c-8a53-456a-9e93-beb3017b4f80: { ...offerDetails }
GroupOffer:f73fb306-0250-4805-b1d1-890d3c6de960: { ...offerDetails }
GroupOffer:fa7a5617-0bc6-46fd-bef3-395661538c44: { ...offerDetails }
GroupOffer:fc1be3a5-baa9-4fff-a48b-d637130e5008: { ...offerDetails }
When I switch over to the inactive filter, this is what merge gets (notice that the existing is populated and set to the previous active cache keys):
LOG -----------args {"input": {"category": "INACTIVE", "limit": 8, "offset": 0}}
LOG -----------existing [{"__ref": "GroupOffer:fa7a5617-0bc6-46fd-bef3-395661538c44"}, {"__ref": "GroupOffer:f73fb306-0250-4805-b1d1-890d3c6de960"}, {"__ref": "GroupOffer:96ef3c51-aa02-4118-aa4c-18fa754ad122"}, {"__ref": "GroupOffer:372cc59c-8a53-456a-9e93-beb3017b4f80"}, {"__ref": "GroupOffer:fc1be3a5-baa9-4fff-a48b-d637130e5008"}]
LOG -----------incoming [{"__ref": "GroupOffer:3ce37911-8a6b-4bfa-937b-5481149e6579"}, {"__ref": "GroupOffer:7630f3c6-130a-4bf5-9155-341f7047e325"}, {"__ref": "GroupOffer:f99025f2-689b-4aca-b546-61e4fa45ae5c"}, {"__ref": "GroupOffer:ecb621a2-576b-4d8b-9623-d538fdb4ad08"}, {"__ref": "GroupOffer:41005df3-cafa-4c76-8582-6508343a8e3f"}, {"__ref": "GroupOffer:e7edae04-5460-43af-acc9-e0476ea8d996"}, {"__ref": "GroupOffer:2af859a8-4cde-438e-9d99-18dfa936d76d"}, {"__ref": "GroupOffer:379109a1-d666-4077-b89c-ae35d1280cd1"}]
And in the cache itself you see the old and new keys:
GroupOffer:2af859a8-4cde-438e-9d99-18dfa936d76d: { ...offerDetails }
GroupOffer:3ce37911-8a6b-4bfa-937b-5481149e6579: { ...offerDetails }
GroupOffer:96ef3c51-aa02-4118-aa4c-18fa754ad122: { ...offerDetails }
GroupOffer:372cc59c-8a53-456a-9e93-beb3017b4f80: { ...offerDetails }
GroupOffer:7630f3c6-130a-4bf5-9155-341f7047e325: { ...offerDetails }
GroupOffer:41005df3-cafa-4c76-8582-6508343a8e3f: { ...offerDetails }
GroupOffer:379109a1-d666-4077-b89c-ae35d1280cd1: { ...offerDetails }
GroupOffer:e7edae04-5460-43af-acc9-e0476ea8d996: { ...offerDetails }
GroupOffer:ecb621a2-576b-4d8b-9623-d538fdb4ad08: { ...offerDetails }
GroupOffer:f73fb306-0250-4805-b1d1-890d3c6de960: { ...offerDetails }
GroupOffer:f99025f2-689b-4aca-b546-61e4fa45ae5c: { ...offerDetails }
GroupOffer:fa7a5617-0bc6-46fd-bef3-395661538c44: { ...offerDetails }
GroupOffer:fc1be3a5-baa9-4fff-a48b-d637130e5008: { ...offerDetails }
And this is what the relevant portion of my field policy looks like:
groupOfferQuery: {
keyArgs: ['category'],
merge(existing, incoming, { args, cache }) {
console.log('-----------args', args);
console.log('-----------existing', existing);
console.log('-----------incoming', incoming);
console.log('-----------cache', cache.extract());
const merged = existing ? existing.slice(0) : [];
The UI does seem to be “working” now that I switched from cursor to offset pagination, but I suspect it’s only working because the offset is reset back to 0, and is overriding the sliced existing array. With cursor style, since there’s no overwrite, you end up getting old and new results.