Evaluating expression inside query and expose in the final output

I have query which would find all parent nodes in the tree. The nodes which are not children to any other nodes.

{
categories(func:eq(dgraph.type, “Category”)) @filter(eq(count(~child), 0)){
name
namePath
subcategories: child {
name
namePath
<<isLeaf as count(child) > 0>>
}
}
}

My schema looks like this

type Category {
name: string
namePath: string
maps_to: [uid]
child: [uid]
}

I am trying to find if the children of the parent are leaf nodes or not. The nodes do not have any more children. Is there a way to add a isLeaf flag to get the status of leaf nodes. Is there a way to evaluate an condition and return the boolean as field in the output

Change this to

@filter(NOT has(~child))

it is better, more performative.

I’m not sure I understand it correctly, but you can try using math func to get true/false statements.

e.g:

{
  q(func: uid(0x1)){
    h as math(10)
    test: math(h > 1)
  }
}

If you use a variable in the first position of the math function. You will get true/false result.

For example, the variable “h” you can put in a count func. If the value is greater than 1 it will return True.

This is perfect it worked for me. It would be great if such things are documented or I did not read the documentation properly.

Thanks for the answer !!!