You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm stuck with implementing pagination feature since the docs from this library (v2) and the official docs from apollo are diffrent regarding the topic on how to handle pagination.
What I found so far from Apollo website:
In Apollo client 2, you would also provide fetchMore an updateQuery function, which was responsible for merging the followup query's results with your existing cached data. In Apollo Client 3, you instead define custom merge functions. This enables you to specify all of your pagination logic in a central location, instead of duplicating it everywhere you call fetchMore.
So I did that:
new InMemoryCache({
typePolicies: {
Query: {
fields: {
getContact: {
read(existing, { args: { page, limit }}) {
const offset = page * 50;
// A read function should always return undefined if existing is
// undefined. Returning undefined signals that the field is
// missing from the cache, which instructs Apollo Client to
// fetch its value from your GraphQL server.
return existing //&& existing.slice(offset, offset + limit);
},
// The keyArgs list and merge function are the same as above.
keyArgs: false,
merge(existing, incoming, { args: { page = 0 }}) {
const offset = page * 50;
const merged = existing ? existing.slice(0) : [];
for (let i = 0; i < incoming.items.length; ++i) {
merged[offset + i] = incoming.items[i];
}
return merged;
}
},
},
},
},
})
Since I do use Apollo client v3 under the hood since I use the library apollo-angular in version 2.4.0.
Yet the documentation here says to still use the updateQuery function.
My problem now is that this gets triggered but within the updateQuery function the 'prev' field seems to be only the cache-references to the cached objects and the fetchMoreResult gives me the concrete result of the requested objects... so I do not understand how to handle the two different object types..
Can someone help me with one official functional version of pagination ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm stuck with implementing pagination feature since the docs from this library (v2) and the official docs from apollo are diffrent regarding the topic on how to handle pagination.
What I found so far from Apollo website:
In Apollo client 2, you would also provide fetchMore an updateQuery function, which was responsible for merging the followup query's results with your existing cached data. In Apollo Client 3, you instead define custom merge functions. This enables you to specify all of your pagination logic in a central location, instead of duplicating it everywhere you call fetchMore.
So I did that:
Yet my listener does not return any new values
Since I do use Apollo client v3 under the hood since I use the library apollo-angular in version 2.4.0.
Yet the documentation here says to still use the updateQuery function.
My problem now is that this gets triggered but within the updateQuery function the 'prev' field seems to be only the cache-references to the cached objects and the fetchMoreResult gives me the concrete result of the requested objects... so I do not understand how to handle the two different object types..
Can someone help me with one official functional version of pagination ?
Beta Was this translation helpful? Give feedback.
All reactions