Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Fix Regression where variables passed in graphql HOC options were not merged with mutation variables #2216

Merged
merged 7 commits into from
Sep 21, 2018

Conversation

samginn
Copy link
Contributor

@samginn samginn commented Jul 25, 2018

Prior to 2.0, variables passed in via the graphql HOC were merged with the variables passed into the mutation function directly. After 2.0, this no longer happens and variables included within the graphql HOC are dropped. This resulted in a breaking change for my app as we use this pattern consistently across the codebase.

Here's an example:

const Component = ({ mutate }) => {
   return (<div onClick={() => mutate({ variables: { second: 2 } })}>Hi</div>)
}

graphql(MUTATION_DOCUMENT, {
  options: () => ({ variables: { first: 1 } })
})(Component)

In this example, the mutation would only receive the variable second: 2 and fail to incorporate the variable first: 1. If you do not include any variables within the mutate call (just call mutate()), then first: 1 is successfully included, but when including any variables within mutate, they are overwritten rather than merged. This PR reverts that behavior to where they will be merged together.

I've included a test to test for this scenario as well.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • If this was a change that affects the external API used in GitHunt-React, update GitHunt-React and post a link to the PR in the discussion.

@apollo-cla
Copy link

@samginn: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @samginn!

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 this pull request may close these issues.

3 participants