Skip to content

Instantly share code, notes, and snippets.

@nicolaslopezj
Created October 12, 2016 23:41
Show Gist options
  • Save nicolaslopezj/4b4a1c730af9ed480da0a0313aaaac4d to your computer and use it in GitHub Desktop.
Save nicolaslopezj/4b4a1c730af9ed480da0a0313aaaac4d to your computer and use it in GitHub Desktop.
/* Before */
@withMutation(gql`mutation save ($title: String, $description: String) {
saveData (title: $title, description: $description) {
title
description
}
}`)
class Save extends React.Component {
async save () {
try {
const result = await this.props.mutate({
title: this.state.title,
description: this.state.description
})
console.log('Success', result.data.saveData)
} catch (error) {
console.log('Error', error)
}
}
}
/* After */
@withMutation(gql`mutation save ($title: String, $description: String) {
saveData (title: $title, description: $description) {
title
description
}
}`)
class Save extends React.Component {
async save () {
try {
const result = await this.props.save({
title: this.state.title,
description: this.state.description
})
console.log('Success', result.saveData)
} catch (error) {
console.log('Error', error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment