Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Last active August 25, 2017 15:06
Show Gist options
  • Save gc-codesnippets/f4b4ad9687a4016ee93bfcb36a8fa63a to your computer and use it in GitHub Desktop.
Save gc-codesnippets/f4b4ad9687a4016ee93bfcb36a8fa63a to your computer and use it in GitHub Desktop.
export default class ChangeTodoStatusMutation extends Relay.Mutation {
static fragments = {
todo: () => Relay.QL`
fragment on Todo {
id,
complete
}
`,
viewer: () => Relay.QL`
fragment on Viewer {
id,
}
`,
}
getMutation () {
return Relay.QL`mutation{updateTodo}`
}
getFatQuery () {
return Relay.QL`
fragment on UpdateTodoPayload {
todo {
complete,
},
viewer {
allTodoes,
},
}
`
}
getConfigs () {
return [{
type: 'FIELDS_CHANGE',
fieldIDs: {
todo: this.props.todo.id,
viewer: this.props.viewer.id,
},
}]
}
getVariables () {
return {
complete: this.props.complete,
id: this.props.todo.id,
}
}
getOptimisticResponse () {
var viewerPayload = {id: this.props.viewer.id}
return {
todo: {
complete: this.props.complete,
id: this.props.todo.id,
},
viewer: viewerPayload,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment