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

Variables set on mutate function override one set on useMutation hook #6619

Closed
0777101 opened this issue Jul 16, 2020 · 14 comments · Fixed by #6927
Closed

Variables set on mutate function override one set on useMutation hook #6619

0777101 opened this issue Jul 16, 2020 · 14 comments · Fixed by #6927

Comments

@0777101
Copy link

0777101 commented Jul 16, 2020

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 b273d03, specifically by removing this code:

const mutateVariables = Object.assign(
  {},
  variables,
  mutateOptions.variables
);
@yograf
Copy link

yograf commented Jul 21, 2020

I'm trying to figure out if this is a bug or intended?
from the docs "Any options you provide to a mutate function override corresponding options you previously provided to useMutation"
??

@tyler-dot-earth
Copy link

I would also like to know if this is intended behavior; I have several mutations that rely on initially-set variables getting merged with the mutate function automatically. Gonna need to do some extra plumbing as part of the v3 migration if this change is intended behavior.

@ericArbour
Copy link

ericArbour commented Aug 7, 2020

This gave me some issues when migrating to "@apollo/client": "^3.1.2". Interestingly, I verified that useLazyQuery still merges the callback and hook variables together.

@hwillson hwillson self-assigned this Aug 8, 2020
@hwillson
Copy link
Member

hwillson commented Aug 8, 2020

Is this issue still happening with >= @apollo/client@3.1.0? I'm surprised it wasn't fixed by #6715.

@hwillson hwillson added the 🏓 awaiting-contributor-response requires input from a contributor label Aug 8, 2020
@ericArbour
Copy link

@hwillson I just tested with @apollo/client@3.1.3 and can confirm this behavior is still occurring. Thanks!

@0777101
Copy link
Author

0777101 commented Aug 8, 2020

I'm surprised it wasn't fixed by #6715.

@hwillson
That is because compact utility function, used in #6715, doesn't have a recursion. It sets (override) result.variables to the value found in mutationFunctionOptions, but to fix the issue it should merge (combine) it with what was found in this.getOptions()

@hwillson hwillson removed the 🏓 awaiting-contributor-response requires input from a contributor label Aug 8, 2020
@hwillson
Copy link
Member

hwillson commented Aug 8, 2020

Thanks @ericArbour @0777101 - I'll take a closer look.

@Nedomas
Copy link

Nedomas commented Aug 9, 2020

Can confirm that this bug exists at least from >=3.0.0.

@amannn
Copy link
Contributor

amannn commented Aug 28, 2020

I also noticed this behaviour in @apollo/client@3.1.4

@amannn
Copy link
Contributor

amannn commented Aug 28, 2020

I've added a PR which should fix this 🙂

#6927

@Nedomas
Copy link

Nedomas commented Sep 3, 2020

This is a blocking issue for us to migrate to v3 currently. Thanks @amannn! Looking forward for #6927 to be merged.

@ianks
Copy link

ianks commented Sep 22, 2020

we're blocked by this as well. looks likes #6927 was merged. any chance this gets released in v3.2.1?

@Alttaf
Copy link

Alttaf commented Oct 23, 2020

we are blocked by this at the moment too, we really want to move to v3

@hwillson hwillson removed their assignment May 4, 2021
@hwillson
Copy link
Member

hwillson commented May 4, 2021

Let us know if this is still a concern with @apollo/client@latest - thanks!

@hwillson hwillson closed this as completed May 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants