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
In Apollo v3 we have the ability to specify a merge function in a particular type field. The merge function works fine when merging types that are normalized in the Cache, but throws an exception if (for whatever reason) you are attempting to spread the existing data.
For example, when defining a merge policy:
merge: (existing,incoming)=>{if(!existing){returnincoming;}// dummy one just for showcasing purposesreturn{
...existing,};},
Everything works fine if the type of the existing is something that's normalized in the InMemoryCache. If it's not normalized (by missing an id/ _id or by specifying keyFields: false), then I get the following error:
policies.js:246Uncaught(inpromise) TypeError: Cannotassigntoreadonlyproperty'__typename'ofobject'[object Object]'atpolicies.js:246atArray.forEach(<anonymous>)
at Policies.push../node_modules/@apollo/client/cache/inmemory/policies.js.Policies.applyMerges (policies.js:245)
at policies.js:238
at Array.map (<anonymous>)
at Policies.push../node_modules/@apollo/client/cache/inmemory/policies.js.Policies.applyMerges (policies.js:238)
at policies.js:246
at Array.forEach (<anonymous>)
at Policies.push../node_modules/@apollo/client/cache/inmemory/policies.js.Policies.applyMerges (policies.js:245)
at policies.js:246
Funnily enough, if I attempt to spread the incoming instead of the existing, then everything seems fine. I'm including @benjamn since I believe this may relate to his work.
Intended outcome:
Merging of a field should be irrelevant of whether the data is normalized in the cache.
Actual outcome:
If I attempt to write ...existing in the result in the merge function (i.e. ...existing, ...existing.items, etc.) then an error is triggered.
How to reproduce the issue:
It's pretty simple. Define a merge function that returns the example found in the description, for a type that is not normalized in the cache.
Seeing as you worked on data mutations, just wanted to let you know that another issue is still present #6202. I've added a reproduction codesandbox using the latest beta.
In Apollo v3 we have the ability to specify a merge function in a particular type field. The merge function works fine when merging types that are normalized in the Cache, but throws an exception if (for whatever reason) you are attempting to spread the existing data.
For example, when defining a merge policy:
Everything works fine if the type of the
existing
is something that's normalized in the InMemoryCache. If it's not normalized (by missing anid
/_id
or by specifyingkeyFields: false
), then I get the following error:Funnily enough, if I attempt to spread the
incoming
instead of theexisting
, then everything seems fine. I'm including @benjamn since I believe this may relate to his work.Intended outcome:
Merging of a field should be irrelevant of whether the data is normalized in the cache.
We should be allowed to do:
without any issues.
Actual outcome:
If I attempt to write
...existing
in the result in the merge function (i.e....existing
,...existing.items
, etc.) then an error is triggered.How to reproduce the issue:
It's pretty simple. Define a merge function that returns the example found in the description, for a type that is not normalized in the cache.
Versions
System:
OS: macOS 10.15.2
Binaries:
Node: 10.16.0 - /usr/local/bin/node
Yarn: 1.19.0 - /usr/local/bin/yarn
npm: 6.14.2 - /usr/local/bin/npm
Browsers:
Chrome: 81.0.4044.129
Firefox: 72.0.2
Safari: 13.0.4
npmPackages:
@apollo/client: 3.0.0-beta.41 => 3.0.0-beta.41
apollo-link-error: ^1.1.12 => 1.1.12
The text was updated successfully, but these errors were encountered: