apollo-client
apollo-client copied to clipboard
Mutations receive raw data without field read type policies applied
Intended outcome:
I have defined a read
field policy for a type. When I call a mutation through the client (not the hook) using client.mutate(...)
, I expect to have that field policy applied to the promise's result. In this case, the object with the read policy is an embedded object without any key fields.
I rewrote this to use useMutation
, and its onCompleted
callback also receives the raw data without the read policy applied.
Actual outcome:
The returned promise receives the raw data from the server without the read policy applied even though the read policy is executed before resolving the promise.
~~The useMutation
hook behaves as expected.~~ Strangely, so does client.query(...)
.
How to reproduce the issue:
I have created reproduction sandboxes for client.mutate
and useMutation
. The important bits are in index.jsx
, specifically renamePerson
and const client = ...
.
- Open the console when running it
- You'll see the three date strings get converted in the read policy on load.
- Enter a name and click the Rename Second Person button.
- You'll see the updated date string get converted and a message saying the
time
field is astring
. It should be aDate
object which is what the read policy returns.
Versions
The sandbox uses version 3.6.8. This is from my application:
System:
OS: Linux 5.13 Ubuntu 20.04.5 LTS (Focal Fossa)
Binaries:
Node: 14.19.0 - ~/.asdf/installs/nodejs/14.19.0/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 6.14.16 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Chrome: 105.0.5195.52
Firefox: 104.0
npmPackages:
@apollo/client: ^3.5.10 => 3.5.10
any news there or how to patch it?
We now have one instance where this happens during a query. It depends on the data somehow and is repeatable. For one entity type, some instances have this issue but not all.
Is there any clue so far what's causing it?
Edit: This new query issue turned out to be caused by an attached entity that implemented an interface, and not adding it in the list of possibleTypes
for the interface. The mutation sandbox I created above does not use interfaces, but perhaps it's related.
I thought I was crazy. Still doing this in 3.7.7.
I'm also facing this issue (using useMutation
). Any plan to fix this?
A workaround is to add:
defaultOptions: {
mutate: {
update: () => {},
}
}
when initializing ApolloClient
Facing a similar issue and while the workaround suggested by @such does work it would be better to get a fix for this issue instead.