Skip to content

v4: Fixes useMutation not taking a Ref #892

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

Merged
merged 1 commit into from
Jan 10, 2020
Merged

Conversation

bbugh
Copy link
Contributor

@bbugh bbugh commented Dec 19, 2019

Currently, useMutation is defined to not allow document or options to be a Ref. It works as expected, it just needs to be unwrapped in mutate. Here is example code that breaks in v4-alpha4, but works after this PR.

const randomName = ref('')

const options = ref({ variables: { id: 1, name: randomName } })

// ❌ v4-alpha4 causes a type error on `options`
// ✅ works correctly after the PR
const { mutate } = useMutation(RandomNameMutation, options)

// button @click="randomizeName"
function randomizeName () {
  randomName.value = Math.random().toString()
  mutate()
}

In this case, clicking the button correctly runs the mutation with a new random name value every time.


This PR resolves one of several issues found while creating a graphql-code-generator plugin for vue-apollo hooks, which can be tracked here.

@bbugh bbugh changed the title Fixes useMutation not taking a Ref v4: Fixes useMutation not taking a Ref Dec 19, 2019
@Akryum Akryum merged commit 0ad08c7 into vuejs:v4 Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants