How to query a tree?

Lets say, a person has friends. And friends have their friends and so no. I want to start from a person, and then list their friends. Its easy using graphql. then I want to find friends upto level N deep and N could be large. Results should be acyclic. Means if alice has a friend bob, then in bob’s result, alice should not appear because bob is alreay part of alice’s result. How do I write a graphql query for it ?

Not really possible with GraphQL cuz it is a highly typed language. BUT, you could use a Custom query with a recurse query and then normalize (flat) the data. So you can create a GraphQL Type for that flat result.