Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutations receive raw data without field read type policies applied #10081

Open
dharkness opened this issue Sep 8, 2022 · 6 comments
Open

Mutations receive raw data without field read type policies applied #10081

dharkness opened this issue Sep 8, 2022 · 6 comments
Labels
🔍 investigate Investigate further

Comments

@dharkness
Copy link

dharkness commented Sep 8, 2022

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 = ....

  1. Open the console when running it
  2. You'll see the three date strings get converted in the read policy on load.
  3. Enter a name and click the Rename Second Person button.
  4. You'll see the updated date string get converted and a message saying the time field is a string.
    It should be a Date 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 
@dharkness dharkness changed the title client.mutate().then() receives raw data without type policies applied Mutations receive raw data without field read type policies applied Sep 9, 2022
@jpvajda jpvajda added the 🔍 investigate Investigate further label Sep 9, 2022
@daniel-g
Copy link

any news there or how to patch it?

@dharkness
Copy link
Author

dharkness commented Feb 27, 2023

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.

@timscott
Copy link

timscott commented Oct 5, 2023

I thought I was crazy. Still doing this in 3.7.7.

@such
Copy link

such commented Jan 5, 2024

I'm also facing this issue (using useMutation). Any plan to fix this?

@such
Copy link

such commented Jan 6, 2024

A workaround is to add:

defaultOptions: {
  mutate: {
    update: () => {},
  }
}

when initializing ApolloClient

@Geccles
Copy link

Geccles commented Jan 29, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 investigate Investigate further
Projects
None yet
Development

No branches or pull requests

6 participants