fix createComment Mutations

This commit is contained in:
Belen Curcio
2017-04-12 16:51:41 -03:00
parent 3837c316d5
commit e8d9f8aab8
3 changed files with 10 additions and 12 deletions
@@ -14,14 +14,12 @@ export const postComment = graphql(POST_COMMENT, {
fragments: commentView
}),
props: ({ownProps, mutate}) => ({
postItem: ({asset_id, body, parent_id}) =>
mutate({
postItem: comment => {
const {asset_id, body, parent_id, tags = []} = comment;
return mutate({
variables: {
comment: {
asset_id,
body,
parent_id
}
comment
},
optimisticResponse: {
createComment: {
@@ -35,14 +33,14 @@ export const postComment = graphql(POST_COMMENT, {
parent_id,
asset_id,
action_summaries: [],
tags: [],
tags,
status: null,
id: 'pending'
}
}
},
updateQueries: {
AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => {
AssetQuery: (oldData, {mutationResult: {data: {createComment: {comment}}}}) => {
if (oldData.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED') {
return oldData;
@@ -58,8 +56,8 @@ export const postComment = graphql(POST_COMMENT, {
...oldData.asset,
comments: oldData.asset.comments.map((oldComment) => {
return oldComment.id === parent_id
? {...oldComment, replies: [...oldComment.replies, comment]}
: oldComment;
? {...oldComment, replies: [...oldComment.replies, comment]}
: oldComment;
})
}
};
@@ -80,6 +78,7 @@ export const postComment = graphql(POST_COMMENT, {
}
}
})
}
}),
});
@@ -45,7 +45,6 @@ class CommentBox extends Component {
let comment = {
body: this.state.body,
asset_id: assetId,
author_id: authorId,
parent_id: parentId
};
View File