That should work, I’ve done such constructs a number of times - do you perhaps already have something called node
in that session? That’s what the error suggests, at least. What do you get in a new session?
Also, please quote your code, to make it easier to help you.
You can use that - leaves just don’t have children, the array is empty. You can even have a parent
field too - if the parent is equal to the object itself, you’re at the root. It’s also a bit more efficient to do it this way, since there’s no type instability involved anymore, unlike with the union approach.