From 346158da7fba9da7de1a915d5da273023fa06a67 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Thu, 2 May 2019 19:55:54 -0300 Subject: [PATCH] Update to use autogenerated Comment Query - using the custom CommentByPost Query was not returning the author of the Post, therefore the users avatar was not showing up - there are some weird bugs with the comments, if you dblclick on the button, two comments with the same content are created - sometimes the comments appear as the bottom of the list, sometimes they appear three comments from the bottom(?) --- backend/src/resolvers/comments.js | 45 +++++++-------------------- webapp/graphql/CommentQuery.js | 26 ++++++++++++++-- webapp/pages/post/_id/_slug/index.vue | 6 ++-- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js index b2dc0fbcf..56280d6ea 100644 --- a/backend/src/resolvers/comments.js +++ b/backend/src/resolvers/comments.js @@ -3,26 +3,6 @@ import { UserInputError } from 'apollo-server' const COMMENT_MIN_LENGTH = 1 export default { - Query: { - CommentByPost: async (object, params, context, resolveInfo) => { - const { postId } = params - - const session = context.driver.session() - const transactionRes = await session.run(` - MATCH (comment:Comment)-[:COMMENTS]->(post:Post {id: $postId}) - RETURN comment {.id, .contentExcerpt, .createdAt} ORDER BY comment.createdAt ASC`, { - postId - }) - - session.close() - let comments = [] - transactionRes.records.map(record => { - comments.push(record.get('comment')) - }) - - return comments - } - }, Mutation: { CreateComment: async (object, params, context, resolveInfo) => { const content = params.content.replace(/<(?:.|\n)*?>/gm, '').trim() @@ -31,29 +11,26 @@ export default { throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`) } const { postId } = params - delete params.postId const comment = await neo4jgraphql(object, params, context, resolveInfo, false) const session = context.driver.session() await session.run(` - MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}) - MERGE (post)<-[:COMMENTS]-(comment) - RETURN comment {.id, .content}`, { + MATCH (author:User {id: $userId}), (comment:Comment {id: $commentId}) + MERGE (comment)<-[:WROTE]-(author) + RETURN author`, { + userId: context.user.id, + commentId: comment.id + } + ) + await session.run(` + MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}) + MERGE (post)<-[:COMMENTS]-(comment) + RETURN post`, { postId, commentId: comment.id } ) - - await session.run(` - MATCH (comment:Comment {id: $commentId}), (author:User {id: $userId}) - MERGE (comment)<-[:WROTE]-(author) - RETURN comment {.id, .content}`, { - commentId: comment.id, - userId: context.user.id - } - ) - session.close() return comment diff --git a/webapp/graphql/CommentQuery.js b/webapp/graphql/CommentQuery.js index 299916823..0e61a8a6c 100644 --- a/webapp/graphql/CommentQuery.js +++ b/webapp/graphql/CommentQuery.js @@ -1,12 +1,34 @@ import gql from 'graphql-tag' export default app => { + const lang = app.$i18n.locale().toUpperCase() return gql(` - query CommentByPost($postId: ID!) { - CommentByPost(postId: $postId) { + query Comment($postId: ID) { + Comment(postId: $postId) { id contentExcerpt createdAt + author { + id + slug + name + avatar + disabled + deleted + shoutedCount + contributionsCount + commentsCount + followedByCount + followedByCurrentUser + location { + name: name${lang} + } + badges { + id + key + icon + } + } } } `) diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index f83925f68..7ae683425 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -179,7 +179,7 @@ export default { this.post = post[0] || {} this.title = this.post.title }, - CommentByPost(comments) { + Comment(comments) { this.comments = comments || [] } }, @@ -291,11 +291,11 @@ export default { return this.$store.getters['auth/user'].id === id }, addComment(comment) { - this.$apollo.queries.CommentByPost.refetch() + this.$apollo.queries.Comment.refetch() } }, apollo: { - CommentByPost: { + Comment: { query() { return require('~/graphql/CommentQuery.js').default(this) },