question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variables set on mutate function override one set on useMutation hook

See original GitHub issue

Intended outcome:

Variables passed to mutate function and variables set on useMutation merged together into one object

Actual outcome:

Variables passed to mutate function override what was set on useMutation

How to reproduce the issue:

const [updateThing] = useMutation(UPDATE_THIS_GQL, {
  variables: {
    id: thingId
  }
});

...

const result = await updateThing({
  variables: {
    ...otherValuesButId
  }
});

Versions

I believe that this was introduced by https://github.com/apollographql/apollo-client/commit/b273d033d6bebddb5fcf4e501e248a0e773e452b, specifically by removing this code:

const mutateVariables = Object.assign(
  {},
  variables,
  mutateOptions.variables
);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Nedomascommented, Sep 3, 2020

This is a blocking issue for us to migrate to v3 currently. Thanks @amannn! Looking forward for https://github.com/apollographql/apollo-client/pull/6927 to be merged.

2reactions
amannncommented, Aug 28, 2020

I’ve added a PR which should fix this 🙂

https://github.com/apollographql/apollo-client/pull/6927

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
variables. Any option you pass here overrides any existing value for that option that you passed to useMutation . The mutate function returns...
Read more >
useMutation | TanStack Query Docs
The mutation function you can call with variables to trigger the mutation and optionally override options passed to useMutation . variables: TVariables.
Read more >
Mutations - Client (React) - Apollo GraphQL Docs
This article also assumes that you've already set up Apollo Client and have ... In addition to a mutate function, the useMutation hook...
Read more >
useMutation · Morrys Repositories
This package provides a useMutation Hook. ... function MyComponentWithHook({ myValue }) { const [mutate, { loading }] = useMutation( ...
Read more >
Mutations with useMutation Apollo Client - React Tutorial 66
FREE React Course (download & bonus content) - https://calcur.tech/free-react-courseReact YouTube Playlist ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found