Children info how to get

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}"
        }
    ]
}

Can you provide a script to generate some test data?

every children and parent userinfo who is comment

    "results": [
        {
            "text": "1 ",
            "createdAt": "Tue Jan 23 2024 17:31:03 GMT+0530 (India Standard Time)",
            "deletedAt": "",
            "publicId": "3577764935909376",
            "children": [
                {
                    "text": "2 ",
                    "createdAt": "Tue Jan 23 2024 17:32:12 GMT+0530 (India Standard Time)",
                    "userId": "3575055351656448",
                    "deletedAt": "",
                    "publicId": "3577765079138304",
                    "children": [
                        {
                            "text": "3 ",
                            "createdAt": "Tue Jan 23 2024 17:43:33 GMT+0530 (India Standard Time)",
                            "userId": "3575189734199296",
                            "deletedAt": "",
                            "publicId": "3577766507327488",
                            "children": [
                                {
                                    "text": "4 ",
                                    "createdAt": "Tue Jan 23 2024 19:09:43 GMT+0530 (India Standard Time)",
                                    "userId": "3575189734199296",
                                    "deletedAt": "",
                                    "publicId": "3577777351069696",
                                    "commentId": "3577766507327488"
                                }
                            ],
                            "commentId": "3577765079138304"
                        }
                    ],
                    "commentId": "3577764935909376"
                }
            ],
            "userInfo": {
                "name": "Abhishek Badole"
            },
            "postId": "3575196306686565}"
        }
    ]
}
![Screenshot from 2024-01-24 10-38-19|690x350](upload://aTJkAgGKVlpfzbStB2bdNXGGRdE.png)
![Screenshot from 2024-01-24 10-38-08|690x350](upload://qKdWATCsbMjcfp4856wRMF4fYqB.png)


**children userinfo also get details help **
**


**

    "results": [
        {
            "text": "p1",
            "createdAt": "Wed Jan 24 2024 16:59:00 GMT+0530 (India Standard Time)",
            "deletedAt": "",
            "publicId": "3577942097330176",
            "children": [
                {
                    "text": "c1",
                    "createdAt": "Wed Jan 24 2024 16:59:33 GMT+0530 (India Standard Time)",
                    "userId": "9995055351656456",
                    "deletedAt": "",
                    "publicId": "3577942165340160",
                    "commentId": "3577942097330176"
                }
            ],
            "userInfo": {
                "name": "Abhishek Badole"
            },
            "postId": "3575196306686565}"
        },
        {
            "text": "p1",
            "createdAt": "Wed Jan 24 2024 16:59:00 GMT+0530 (India Standard Time)",
            "deletedAt": "",
            "publicId": "3577942097330176",
            "children": [
                {
                    "text": "c1",
                    "createdAt": "Wed Jan 24 2024 17:20:43 GMT+0530 (India Standard Time)",
                    "userId": "9995055351656456",
                    "deletedAt": "",
                    "publicId": "3577944829894656",
                    "commentId": "3577942097330176"
                }
            ],
            "userInfo": {
                "name": "Abhishek Badole"
            },
            "postId": "3575196306686565}"
        }
    ]
} ```

Do you have a cypher script that I can run to create the data on my side.

CREATE (:User {name: "user1018", publicId: "'9995055351656456'"})-[:HAS_COMMENT {userId: "'9995055351656456'"}]->(n1:Comment)-[:POST_COMMENT]->(:Post {postId: "'3575196306686565'"})<-[:POSTED]-(:User),
(:User)-[:HAS_COMMENT {userId: "'3575189734199296'"}]->(:Comment)-[:REPLIED_TO {userId: "'3575189734199296'"}]->(n1)




MATCH path0 = (:User {publicId: '9995055351656456'})-[:HAS_COMMENT {userId: '9995055351656456'}]->(n1:Comment)-[:POST_COMMENT]->(:Post {postId: '3575196306686565'})<-[:POSTED]-(:User),
path1 = (:User)-[:HAS_COMMENT {userId: '3575189734199296'}]->(:Comment)-[:REPLIED_TO {userId: '3575189734199296'}]->(n1)
RETURN path0 ,path1




{
    "results": [
        {
            "text": "P",
            "createdAt": "Wed Jan 24 2024 18:56:03 GMT+0530 (India Standard Time)",
            "deletedAt": "",
            "publicId": "3577956824072192",
            "children": [
                {
                    "text": "c1",
                    "createdAt": "Wed Jan 24 2024 19:06:00 GMT+0530 (India Standard Time)",
                    "userId": "3575189734199296",
                    "deletedAt": "",
                    "publicId": "3577958077190144",
                    "commentId": "3577956824072192"
                }
            ],
            "userInfo": {
                "name": "user1020"
            },
            "postId": "3575196306686565}"
        }
    ]
}  parent userinfo      children inside children userinfo

The test data was not as extensive as your sample response. I added one extra comment to a comment. I also added some properties to make it easier to identify each entity in the response.

I did not wrap the single entities in a list, as you have it in your response. None of these are lists, so it seems odd. You can wrap any entity you want in square brackets to have them return as lists.

I strongly suggest you do not use identifiers in relationships to link related nodes. Just use the relationship itself.

Anyways, he is a final attempt.

Test data:

CREATE (:User {name: "user1018", publicId: "9995055351656456"})-[:HAS_COMMENT {userId: "9995055351656456"}]->(n1:Comment{name:"parent comment"})-[:POST_COMMENT]->(:Post {postId: "3575196306686565"})<-[:POSTED]-(:User{publicId: '123456789', name:"poster"}),
(:User{publicId: '987654321', name:"sally"})-[:HAS_COMMENT {userId: "3575189734199296"}]->(n2:Comment{name:"child comment"})-[:REPLIED_TO {userId: "3575189734199296"}]->(n1),
(:User{publicId: '5566778899', name:"gregg"})-[:HAS_COMMENT {userId: "3575189734199456"}]->(:Comment{name:"child2 comment"})-[:REPLIED_TO {userId: "3575189734199296"}]->(n2)

Query:

match (post:Post {postId: '3575196306686565'})
match (post)<-[:POST_COMMENT]-(comment:Comment)
with post, comment, reverse([(comment)<-[:REPLIED_TO*1..]-(n:Comment)|n]) as children
with post, comment, head(children) as head, tail(children) as tail
return post{
    .*,
    userInfo: [(post)<-[:POSTED]-(user:User)|properties(user)][0],
    comment: comment{
        .*,
        userInfo:[(u:User)-[:HAS_COMMENT]->(comment)|properties(u)][0],
        children: reduce(
            s=head{.*, userInfo:[(u:User)-[:HAS_COMMENT]->(head)|properties(u)][0]}, 
            i in tail | 
            i{.*, userInfo:[(u:User)-[:HAS_COMMENT]->(i)|properties(u)][0], children: s})
    }
} as post

Result:

{
  "userInfo": {
    "name": "poster",
    "publicId": "123456789"
  },
  "comment": {
    "userInfo": {
      "name": "user1018",
      "publicId": "9995055351656456"
    },
    "children": {
      "userInfo": {
        "name": "sally",
        "publicId": "987654321"
      },
      "children": {
        "userInfo": {
          "name": "gregg",
          "publicId": "5566778899"
        },
        "name": "child2 comment"
      },
      "name": "child comment"
    },
    "name": "parent comment"
  },
  "postId": "3575196306686565"
}

Even it not exact, the principles you need are demonstrated. The two relevant features are 1) using the reduce method to convert a list into a hierarchical representation of the list elements, and 2) using list comprehension to get the user information for each comment.