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

useMutation data is always undefined, only works in onCompleted #7556

Closed
lsbyerley opened this issue Jan 8, 2021 · 8 comments
Closed

useMutation data is always undefined, only works in onCompleted #7556

lsbyerley opened this issue Jan 8, 2021 · 8 comments

Comments

@lsbyerley
Copy link

lsbyerley commented Jan 8, 2021

Intended outcome:
I am using the below mutation to update a tile object. The data in the onCompleted callback is correctly returning the updated data object. The data I'm returning in my wrapper is always undefined now. This seems to have recently changed and I'm not sure why

const useUpdateTile = () => {
  const [mutation, { data, loading, error }] = useMutation(UPDATE_TILE, {
    errorPolicy: 'all',
    onCompleted: (data) => {
      console.log('LOG: mutation updateTile completed', data);
    },
  });

  console.log('LOG: mutation updateTile', data);

  return {
    updateTile: (input) => {
      mutation({
        variables: {
          input,
        },
      });
    },
    loading,
    error,
    data: data?.updateTile || {},
  };
};

Screen Shot 2021-01-08 at 2 52 48 PM

Actual outcome:

I expect the data returned from the useMutation to contain the updated data object instead of being undefined. This was recently working as intended.

How to reproduce the issue:
Haven't been able to replicate in a codesandbox environment, it must be some other factor.
https://codesandbox.io/s/competent-visvesvaraya-ifzp9?file=/src/App.js

Versions

System:
    OS: macOS 10.15.6
  Binaries:
    Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
    npm: 6.14.10 - ~/mycode/node_modules/.bin/npm
  Browsers:
    Chrome: 85.0.4183.102
    Firefox: 68.11.0
    Safari: 13.1.2
  npmPackages:
    @apollo/client: 3.3.6 => 3.3.6 
@jcreighton jcreighton self-assigned this Apr 21, 2021
@sfratini
Copy link

Seems to be solved by this, but I cant see a release with it #8018

@dylanwulf
Copy link
Contributor

@sfratini The change in that PR is available in v3.3.16: https://github.com/apollographql/apollo-client/blob/main/CHANGELOG.md#apollo-client-3316

@brainkim brainkim self-assigned this Jun 22, 2021
@sfratini
Copy link

FYI this is still an issue on 3.3.20.

@benjamn
Copy link
Member

benjamn commented Jun 25, 2021

@sfratini I don't see it when I update to 3.3.20 in https://codesandbox.io/s/nostalgic-firefly-rjhw7. Could you tweak that reproduction until it demonstrates the issue you're seeing?

@sfratini
Copy link

@sfratini I don't see it when I update to 3.3.20 in https://codesandbox.io/s/nostalgic-firefly-rjhw7. Could you tweak that reproduction until it demonstrates the issue you're seeing?

Actually I take that back. It does work, it just seems to show the data and then reset the value to undefined but it could just be my environment refreshing the state.

@brainkim brainkim mentioned this issue Aug 16, 2021
14 tasks
@brainkim brainkim removed their assignment Aug 18, 2021
@brainkim
Copy link
Contributor

Closing because it seems like this has been fixed at some point by some person 😶

@ichabanivan
Copy link

How have you fixed that?

@up209d
Copy link

up209d commented May 18, 2022

The problem still insists and is inconsistent

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants