It depends on how you want to use this info.
For example if it is in a client logic a query like
{
list(func: uid(0x6241ae)) @recurse @normalize{
name:name
subsidiary
}
}
will return (in my case I have A->B->C)
{
"data": {
"list": [
{
"name": [
"A",
"B",
"C"
]
}
]
},
With that, data["list"][0]["name"].length corresponds to the depth of the traversal.
More details needed to see if variables and math function could help you too…