Following the Paginations Docs, I was able to get pagination working well:
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
feed: {
keyArgs: [],
merge(existing, incoming, { args: { offset = 0 }}) {
// Slicing is necessary because the existing data is
// immutable, and frozen in development.
const merged = existing ? existing.slice(0) : [];
for (let i = 0; i < incoming.length; ++i) {
merged[offset + i] = incoming[i];
}
return merged;
},
},
},
},
},
});
However, if I’m making another separate query but for the same field (using the code above as an example, “feed” is being queried more than once, aside from fetchMore
), the two results get merged in.
I was able to “fix” this by using fetchPolicy: "no-cache"
with the second query (useQuery
), but is there any way to avoid this without needing to use fetchPolicy: "no-cache"
?