diff --git a/backend/src/graphql-schema.js b/backend/src/graphql-schema.js index aff10729f..bad277721 100644 --- a/backend/src/graphql-schema.js +++ b/backend/src/graphql-schema.js @@ -23,7 +23,8 @@ export const resolvers = { Query: { ...statistics.Query, ...userManagement.Query, - ...notifications.Query + ...notifications.Query, + ...comments.Query }, Mutation: { ...userManagement.Mutation, diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js index 5446278d1..b3350ec8e 100644 --- a/backend/src/resolvers/comments.js +++ b/backend/src/resolvers/comments.js @@ -1,6 +1,26 @@ import { neo4jgraphql } from 'neo4j-graphql-js' 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}`, { + postId + }) + + session.close() + let comments = [] + transactionRes.records.map(record => { + comments.push(record.get('comment')) + }) + + return comments + } + }, Mutation: { CreateComment: async (object, params, context, resolveInfo) => { const { postId } = params diff --git a/backend/src/schema.graphql b/backend/src/schema.graphql index 99bcd4533..4638fbd0d 100644 --- a/backend/src/schema.graphql +++ b/backend/src/schema.graphql @@ -16,6 +16,7 @@ type Query { LIMIT $limit """ ) + CommentByPost(postId: ID!): [Comment]! } type Mutation { # Get a JWT Token for the given Email and password