Skip to content

Instantly share code, notes, and snippets.

@ChrisMLee
Last active November 14, 2015 22:47
Show Gist options
  • Save ChrisMLee/a6b8fe94f1782ba07abe to your computer and use it in GitHub Desktop.
Save ChrisMLee/a6b8fe94f1782ba07abe to your computer and use it in GitHub Desktop.
Mutation only updating messages for individual conversation, but not Conversations for User
createMessage(){
Relay.Store.update(new CreateMessageMutation({
user: this.props.user,
conversation: foundEdge.node,
receiverId: receiverId,
body: this.state.curText
}), {onFailure, onSuccess});
}
export default Relay.createContainer(Conversation, {
fragments: {
user: () => Relay.QL`
fragment on User {
id
rails_id
username
email
conversations(first:100){
edges{
node{
id
rails_id
last_message_time
seller{
rails_id
username
}
buyer{
rails_id
username
}
${CreateMessageMutation.getFragment('conversation')}
messages(first:100){
edges{
node{
body
created_at
user{
rails_id
username
}
}
}
}
}
}
}
${CreateMessageMutation.getFragment('user')}
}
`,
},
});
export default class CreateMessageMutation extends Relay.Mutation {
static fragments = {
// TODO update 'read' field in DB
conversation: () => Relay.QL`
fragment on Conversation {
id,
last_message_time
}
`,
user: () => Relay.QL`
fragment on User {
id
}
`,
};
getMutation() {
return Relay.QL`mutation{createMessage}`;
}
getFatQuery() {
return Relay.QL`
fragment on CreateMessagePayload {
MessageEdge,
conversation{
id
last_message_time
messages{
edges{
node{
id
}
}
}
},
user {
conversations(first: 100) {
edges {
node {
last_message_time
messages{
edges{
node{
id
}
}
}
}
}
}
}
}
`;
}
getConfigs() {
return [{
type: 'FIELDS_CHANGE',
fieldIDs: {
user: this.props.user.id,
},
},
{
type: 'RANGE_ADD',
parentName: 'conversation',
parentID: this.props.conversation.id,
connectionName: 'messages',
edgeName: 'MessageEdge',
rangeBehaviors: {
'': 'append',
},
}];
}
getVariables () {
return {
senderId: this.props.user.id,
receiverId: this.props.receiverId,
conversationId: this.props.conversation.id,
body: this.props.body
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment