If you have tree-like collections you can use the children
and parent
attributes to find the top-level objects of the collection and then navigate in depth:
query {allCategories(filter: {parent: {exists: false}}) {namechildren {namechildren {namechildren {name}}}}}