children info how to get REPLIED_To inside userId reply comment2 alsho show userinfo
match(post:Post{postId:'3575196306686565'})<-[:POST_COMMENT]-(n:Comment)
OPTIONAL MATCH (n)<-[r1:HAS_COMMENT]-(parentAuthor:User)
WHERE parentAuthor.publicId = r1.userId
match p=(n)<-[:REPLIED_TO*0..]-(m:Comment)
where not exists((m)<-[:REPLIED_TO]-(:Comment))
with properties(n) as comment,parentAuthor, reverse(nodes(p)[1..]) as children
return
comment{ text: comment.text,
createdAt: comment.createdAt,
deletedAt: comment.deletedAt,
publicId: comment.publicId,
postId: comment.postId,
userInfo: parentAuthor { .name ,.publicId},
children: [reduce(s = properties(head(children)), i IN tail(children) |
i{
text: i.text,
createdAt: i.createdAt,
deletedAt: i.deletedAt,
publicId: i.publicId,
userInfo: COALESCE(
HEAD([(i)<-[:HAS_COMMENT]-(childAuthor:User) | childAuthor {.name}]),
{}
)
,
children:[ s ]
}
)]}
as results
`; ```
{
"results": [
{
"text": "main comment",
"createdAt": "Tue Jan 23 2024 12:16:41 GMT+0530 (India Standard Time)",
"deletedAt": "",
"publicId": "3577725379014656",
"children": [
{
"text": "reply comment1",
"createdAt": "Tue Jan 23 2024 12:18:02 GMT+0530 (India Standard Time)",
"deletedAt": "",
"publicId": "3577725548511232",
"children": [
{
"text": "reply comment2",
"createdAt": "Tue Jan 23 2024 12:18:46 GMT+0530 (India Standard Time)",
"userId": "9995055351656460",
"deletedAt": "",
"publicId": "3577725640982528",
"commentId": "3577725548511232"
}
],
"userInfo": {
"name": "rohan"
}
}
],
"userInfo": {
"name": "user1024",
"publicId": "9995055351656460"
},
"postId": "3575196306686565}"
}
]
}