Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> GraphQL doesn't allow for recursive types.

It does, this schema works:

  type Item {
    id: ID!
    children: [Item!]!
  }

  type Query {
    root: Item!
  }
GraphQL queries describe the shape of the response, so with this schema it's not possible to ask recursively for "the full tree up to an arbitrary depth". One way to solve this would be to add a "descendants" field that returns a list of all the children, grand-children...


It is not infinitely recursive. It supports nested structures as you show but only up to a predefined depth.

IE:

    fragment CategoriesRecursive on Category {
      subcategories {
        ...SubcategoryFields
        subcategories {
          ...SubcategoryFields
          subcategories {
            ...SubcategoryFields
          }
        }
      }
    }

So you have to build your schema with a maximum supported depth. This is not infinitely recursive which is a limitation of the GQL type system.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: