Last active
November 14, 2015 22:47
-
-
Save ChrisMLee/a6b8fe94f1782ba07abe to your computer and use it in GitHub Desktop.
Mutation only updating messages for individual conversation, but not Conversations for User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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')} | |
} | |
`, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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