|
| 1 | +package graphql.kickstart.tools |
| 2 | + |
| 3 | +import graphql.ExecutionInput |
| 4 | +import graphql.GraphQL |
| 5 | +import org.junit.Test |
| 6 | + |
| 7 | +class PlaceTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + fun shouldHandleGenericsDeepHierarchy() { |
| 11 | + val schema = SchemaParser.newParser() |
| 12 | + .file("Place.graphqls") |
| 13 | + .resolvers(PlaceQuery()) |
| 14 | + .build().makeExecutableSchema() |
| 15 | + |
| 16 | + val graphql = GraphQL.newGraphQL(schema).build() |
| 17 | + val query = "query { places1 { id } places2 { id } }" |
| 18 | + val executionInput = ExecutionInput.newExecutionInput().query(query).build() |
| 19 | + val result = graphql.execute(executionInput) |
| 20 | + |
| 21 | + assert(result.getData<Map<String, List<*>>>()["places1"]?.size == 3) |
| 22 | + assert(result.getData<Map<String, List<*>>>()["places2"]?.size == 2) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +private class PlaceQuery : GraphQLQueryResolver { |
| 27 | + |
| 28 | + fun places1(): List<Place1> = listOf(Place1("1"), Place1("2"), Place1("3")) |
| 29 | + |
| 30 | + fun places2(): List<Place2> = listOf(Place2("4"), Place2("5")) |
| 31 | +} |
| 32 | + |
| 33 | +private abstract class Entity(val id: String? = null) |
| 34 | + |
| 35 | +private abstract class OtherPlace<R : Review<*>>(id: String? = null) : Place<R>(id) { |
| 36 | + val other: String? = null |
| 37 | +} |
| 38 | + |
| 39 | +private abstract class Place<R : Review<*>>(id: String? = null) : Entity(id) { |
| 40 | + val name: String? = null |
| 41 | + val reviews: MutableSet<R>? = null |
| 42 | +} |
| 43 | + |
| 44 | +private class Place1(id: String? = null) : OtherPlace<Review1>(id) |
| 45 | + |
| 46 | +private class Place2(id: String? = null) : OtherPlace<Review2>(id) |
| 47 | + |
| 48 | +private abstract class Review<T : Entity>(id: String? = null) : Entity(id) { |
| 49 | + val rating: Int? = null |
| 50 | + val content: T? = null |
| 51 | +} |
| 52 | + |
| 53 | +private class Review1(id: String? = null) : Review<Place1>(id) |
| 54 | + |
| 55 | +private class Review2(id: String? = null) : Review<Place2>(id) |
0 commit comments