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
The text was updated successfully, but these errors were encountered:
meesfrenkelfrank
changed the title
Incoming and existing data not merging, Apollo 3 pagination with field policies
Incoming and existing cache data not merging, Apollo 3 pagination with field policies
Jan 15, 2022
Maybe you can try to change keyFields: false to keyFields: [], this solve my problem with existing undefined.
new InMemoryCache({
typePolicies: {
GetNodes: {
keyFields: [], // <- this
fields: {
nodes: {
keyArgs: false, // I always set this to false, following the doc, but didn't know what it does
merge(existing = [], incoming: unknown[]) {
console.log('Existing', existing);
console.log('Incoming', incoming);
return [...existing, ...incoming];
},
},
},
},
})
keyArgs: false, // I always set this to false, following the doc, but didn't know what it does
@david-yappeter - Specifying keyFields: false in a type policy disables normalization for that type, so your GetNodes objects will not be normalized at all, but will be stored directly as values (not References) under their parent fields.
Intended outcome:
I have the following GraphQL query:
And configured the cache with a merge function:
I am using Apollo client fetchMore function to be able to fetch more items.
Also I tried to disabling normalization for GetNodes object:
But same issue. Array's are not merging and can't fetch more items in frontend?
Actual outcome:
Now when I inspect console and the frontend, the
incoming
andexisting
arrays are not merging?existing
array is always empty (after fetching more items)?I don't have an
id
field to use on theGetNodes
query.Whats wrong here?
Versions
System:
OS: macOS 11.6.1
Binaries:
Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
Browsers:
Chrome: 97.0.4692.71
Firefox: 95.0.2
Safari: 15.2
npmPackages:
@apollo/client: ^3.3.19 => 3.3.19
The text was updated successfully, but these errors were encountered: