Skip to content

Instantly share code, notes, and snippets.

@0916dhkim
Created January 31, 2021 20:04
Show Gist options
  • Save 0916dhkim/54c6957f1849ab0436557009e5a006f3 to your computer and use it in GitHub Desktop.
Save 0916dhkim/54c6957f1849ab0436557009e5a006f3 to your computer and use it in GitHub Desktop.
How to use mutation
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