Unable to perform threading to particular reply comment

Hi Team,

I’m trying to make a reply to the particular reply comment but its not happening. Its considering as a separate comment and adding a reply to that comment.

Let me explain the scenario in detail with my example and schema.

Schema:

type Post {
  id: ID!
  title: String! @search(by: [fulltext])
  timestamp: DateTime! @search
  body: String!
  comments: [Comment] @hasInverse(field: post)
}

type Comment {    
  id: ID! 
  message: String! @search(by: [fulltext])
  post: Post @hasInverse(field: comments)
  timestamp: DateTime! @search
  replyComment: [Comment] @hasInverse(field: replyComment)
}

Response:

{
    "data": {
        "getPostById": {
            "success": true,
            "message": "PostId is retrieved successfully",
            "data": {
                "id": "0x4bafc",
                "title": "test data",
                "timestamp": "2021-04-20T06:45:46.218Z",           
                "body": " This is my #message",
                "comments": [
                    {
                        "id": "0x4bb00",
                        "message": "test welcome",
                        "timestamp": "2021-04-20T06:47:52.964Z",
                        "replyComment": []
                    },
                    {
                        "id": "0x4bb02",
                        "message": "edited comments",
                        "timestamp": "2021-04-20T06:48:11.2Z",
                        "replyComment": [
                            {
                                "id": "0x4bb04",
                                "message": "reply comment slash",
                                "timestamp": "2021-04-20T06:52:07.692Z"
                            }
                        ]
                    },
                    {
                        "id": "0x4bb04",
                        "message": "reply comment slash",
                        "timestamp": "2021-04-20T06:52:07.692Z",
                        "replyComment": [
                            {
                                "id": "0x4bb06",
                                "message": "edited reply comment slash",
                                "timestamp": "2021-04-20T06:53:41.2Z"
                            }
                        ]
                    }
                ]
            }
        }
    }
}

Let us consider that I’m trying to make a reply comment for the id: “0x4bb04” . Instead of mapping the reply comment under the id: “0x4bb04”, its considering as a separate comment and adding the reply to it. Threading is not happening here.

Expected Response:

{
    "data": {
        "getPostById": {
            "success": true,
            "message": "PostId is retrieved successfully",
            "data": {
                "id": "0x4bafc",
                "title": "test data",
                "timestamp": "2021-04-20T06:45:46.218Z",           
                "body": " This is my #message",
                "comments": [
                    {
                        "id": "0x4bb00",
                        "message": "test welcome",
                        "timestamp": "2021-04-20T06:47:52.964Z",
                        "replyComment": []
                    },
                    {
                        "id": "0x4bb02",
                        "message": "edited comments",
                        "timestamp": "2021-04-20T06:48:11.2Z",
                        "replyComment": [
                            {
                                "id": "0x4bb04",
                                "message": "reply comment slash",
                                "timestamp": "2021-04-20T06:52:07.692Z",
                                "replyComment": [
                                    {
                                        "id": "0x4bb06",
                                        "message": "edited reply comment slash",
                                        "timestamp": "2021-04-20T06:53:41.2Z"
                                    }
                                ]
                            }                 
                        ]
                    }
                ]
            }
        }
    }
}

Kindly help me to fix the issue.

Nested mutation is not happening for more than one level.

Linked Referred:

https://github.com/graphql/graphql-spec/issues/91

Thanks and Regards
Yuvaraj.

Let’s keep this as a new topic.

can you share the mutation that you used?
I used the following mutation and able to create the threading.

mutation {
  addPost(input:[{title:"GraphQL",timestamp:"2021-04-20T06:47:52.964Z",body:"Intro to GraphQL",comments:[
    {
       message:"nice tutorial",
       timestamp:"2021-04-20T06:47:52.964Z",
       replyComment:[{
         message:"yeah but discussion went in some other direction",
         timestamp:"2021-04-20T07:47:52.964Z",
         replyComment:[{
           message:"yupp,instructor seems curious person ",
           timestamp:"2021-04-20T08:47:52.964Z",
        }] 
      }
      ]
      
    }
  ]}]){
    post{
      title
      timestamp
      body
      comments{
        message
        replyComment{
          message
          replyComment{
            message
          }
        }
      }
    }
  }
}

query

query {
  queryPost {
    id
    timestamp
    body
    comments{
      id
      message
      replyComment{
        id
        message
        replyComment{
          id
          message
        }
      }
    }
  }
}

response:

{
  "data": {
    "queryPost": [
      {
        "id": "0x5",
        "timestamp": "2021-04-20T06:47:52.964Z",
        "body": "Intro to GraphQL",
        "comments": [
          {
            "id": "0x2",
            "message": "nice tutorial",
            "replyComment": [
              {
                "id": "0x3",
                "message": "yeah but discussion went in some other direction",
                "replyComment": [
                  {
                    "id": "0x4",
                    "message": "yupp,instructor seems curious person "
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },

You may skip has inverse here, because while querying you will get both parent and child edges(if present) for a node.
replyComment: [Comment] @hasInverse(field: replyComment)

Also , if you query only comments, you will get nested comments multiple times, once at top result and once in a nested object like below.

query:

query {
  queryComment {
      message
      replyComment{
        message
        replyComment{
          message
        }
      }
    }
  }

response

{
  "data": {
    "queryComment": [
      {
        "message": "nice tutorial",
        "replyComment": [
          {
            "message": "yeah but discussion went in some other direction",
            "replyComment": [
              {
                "message": "yupp,instructor seems curious person "
              }
            ]
          }
        ]
      },
      {
        "message": "yeah but discussion went in some other direction",
        "replyComment": [
          {
            "message": "yupp,instructor seems curious person ",
            "replyComment": []
          }
        ]
      },
      {
        "message": "yupp,instructor seems curious person ",
        "replyComment": []
      }
    ]
  },