diff --git a/backend/src/schema/resolvers/comments.js b/backend/src/schema/resolvers/comments.js index 7f3b11da4..d2e296596 100644 --- a/backend/src/schema/resolvers/comments.js +++ b/backend/src/schema/resolvers/comments.js @@ -38,22 +38,41 @@ export default { if (!post) { throw new UserInputError(NO_POST_ERR_MESSAGE) } - const comment = await neo4jgraphql(object, params, context, resolveInfo, false) + const commentWithoutRelationships = await neo4jgraphql( + object, + params, + context, + resolveInfo, + false, + ) - await session.run( + let transactionRes = await session.run( ` MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}), (author:User {id: $userId}) MERGE (post)<-[:COMMENTS]-(comment)<-[:WROTE]-(author) - RETURN post`, + RETURN comment, author`, { userId: context.user.id, postId, - commentId: comment.id, + commentId: commentWithoutRelationships.id, }, ) - session.close() - return comment + const [commentWithAuthor] = transactionRes.records.map(record => { + return { + comment: record.get('comment'), + author: record.get('author'), + } + }) + + const { comment, author } = commentWithAuthor + + const commentReturnedWithAuthor = { + ...comment.properties, + author: author.properties, + } + session.close() + return commentReturnedWithAuthor }, DeleteComment: async (object, params, context, resolveInfo) => { const comment = await neo4jgraphql(object, params, context, resolveInfo, false) diff --git a/webapp/components/comments/CommentForm/index.vue b/webapp/components/comments/CommentForm/index.vue index f105bd5ff..753d09c13 100644 --- a/webapp/components/comments/CommentForm/index.vue +++ b/webapp/components/comments/CommentForm/index.vue @@ -25,6 +25,8 @@