Skip to content

Instantly share code, notes, and snippets.

@KyleAMathews
Created September 9, 2015 18:40
Show Gist options
  • Save KyleAMathews/3b912f440d4c86d2908f to your computer and use it in GitHub Desktop.
Save KyleAMathews/3b912f440d4c86d2908f to your computer and use it in GitHub Desktop.
import Relay from 'react-relay'
export default class ClickButtonMutation extends Relay.Mutation {
static fragments = {
viewer: () => Relay.QL`
fragment on User {
id
buttonClicked
}
`,
};
getMutation() {
return Relay.QL`mutation{clickButton}`;
}
getFatQuery() {
return Relay.QL`
fragment on ClickButtonPayload {
viewer {
buttonClicked
}
}
`;
}
getConfigs() {
return [{
type: 'FIELDS_CHANGE',
fieldIDs: {
viewer: this.props.viewer.id
}
}];
}
getVariables() {
return {
buttonClicked: this.props.buttonClicked,
};
}
getOptimisticResponse() {
console.log('hi from optimistic')
return {
viewer: {
id: this.props.viewer.id,
buttonClicked: !this.props.viewer.buttonClicked
},
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment