mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
- in the first instance, we will be importing posts/comments from the alpha, so to maintain consistency, we've ordered them alike. In the future, we could support user choice of order. - Gives more space for HcCommentForm, user can see comments added to list, helps with mobile responsiveness Co-authored-by: Tirokk <wolle.huss@pjannto.com> Co-authored-by: Mike Aono <aonomike@gmail.com>
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { neo4jgraphql } from 'neo4j-graphql-js'
|
|
import { UserInputError } from 'apollo-server'
|
|
|
|
const COMMENT_MIN_LENGTH = 3
|
|
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()
|
|
|
|
if (!params.content || content.length < COMMENT_MIN_LENGTH) {
|
|
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} characters 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}`, {
|
|
postId,
|
|
commentId: comment.id
|
|
}
|
|
)
|
|
session.close()
|
|
|
|
return comment
|
|
}
|
|
}
|
|
}
|