Add custom CommentByPost query

This commit is contained in:
Matt Rider 2019-04-23 12:23:21 -03:00
parent c6b11319fe
commit 43d6254f3e
3 changed files with 23 additions and 1 deletions

View File

@ -23,7 +23,8 @@ export const resolvers = {
Query: {
...statistics.Query,
...userManagement.Query,
...notifications.Query
...notifications.Query,
...comments.Query
},
Mutation: {
...userManagement.Mutation,

View File

@ -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

View File

@ -16,6 +16,7 @@ type Query {
LIMIT $limit
"""
)
CommentByPost(postId: ID!): [Comment]!
}
type Mutation {
# Get a JWT Token for the given Email and password