Created
January 31, 2021 20:04
-
-
Save 0916dhkim/54c6957f1849ab0436557009e5a006f3 to your computer and use it in GitHub Desktop.
How to use mutation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const titleMutation = graphql` | |
mutation MyComponentTitleMutation( | |
$postId: ID! | |
$title: String! | |
) { | |
changePostTitle(postId: $postId, title: $title) { | |
id | |
title | |
} | |
} | |
`; | |
const MyComponent: FC = () => { | |
const [commitTitleUpdate] = useMutation<MyComponentTitleMutation>(titleMutation); | |
const onClick = () => { | |
commitTitleUpdate({ | |
variables: { | |
postId: 'uniquepostid', | |
title: 'New Title', | |
}, | |
}); | |
} | |
return <button onClick={onClick}>Update Title!</button>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment