americanexpress / nodes

A GraphQL JVM Client - Java, Kotlin, Scala, etc.
Apache License 2.0
307 stars 70 forks source link

Support for recursive relationships #79

Open andlien opened 5 years ago

andlien commented 5 years ago

Hi! Thank you for developing this client!

Is there any way to use nodes with recursive relationships? For instance, is it possible to generate the following query

{
  query {
    cars(id: 1) {
      id
      owner {
        cars {
          id
        }
      }
    }
  }
}

to list all cars owned by the owner of this car?

Currently the query-generation results in a stack overflow

chemdrew commented 5 years ago

Hi Anders,

Right now no, there is no break when recursively generating the query.

I think the cleanest approach to adding this feature would be to add a new annotation to support something like @GraphQLRecursive(depth = 1).

Then in the recursive getChildren() in GraphQLRequestEntity method on line 240 adding a depth parameter with a sane default to break out of