Skip to content

Commit 36a3756

Browse files
committed
add tests for unwrapGenericType to handle generics for deep hierarchy
1 parent 7207d15 commit 36a3756

File tree

11 files changed

+118
-1
lines changed

11 files changed

+118
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.graphql.kickstart</groupId>
66
<artifactId>graphql-java-tools</artifactId>
7-
<version>5.7.2-SNAPSHOT</version>
7+
<version>5.7.3-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>GraphQL Java Tools</name>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package graphql.kickstart.tools.place
2+
3+
abstract class Entity(val id: String? = null)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package graphql.kickstart.tools.place
2+
3+
abstract class OtherPlace<R : Review<*>>(id: String? = null) : Place<R>(id) {
4+
5+
val other: String? = null
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package graphql.kickstart.tools.place
2+
3+
abstract class Place<R : Review<*>>(id: String? = null) : Entity(id) {
4+
5+
val name: String? = null
6+
val reviews: MutableSet<R>? = null
7+
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package graphql.kickstart.tools.place
2+
3+
class Place1(id: String? = null) : OtherPlace<Review1>(id)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package graphql.kickstart.tools.place
2+
3+
class Place2(id: String? = null) : OtherPlace<Review2>(id)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package graphql.kickstart.tools.place
2+
3+
import graphql.ExecutionInput
4+
import graphql.GraphQL
5+
import graphql.kickstart.tools.GraphQLQueryResolver
6+
import graphql.kickstart.tools.SchemaParser
7+
import org.junit.Test
8+
9+
class PlaceQuery : GraphQLQueryResolver {
10+
fun places1(): List<Place1> = listOf(Place1("1"), Place1("2"), Place1("3"))
11+
fun places2(): List<Place2> = listOf(Place2("4"), Place2("5"))
12+
}
13+
14+
class PlaceTest {
15+
16+
@Test
17+
fun shouldHandleGenericsDeepHierarchy() {
18+
val schema = SchemaParser.newParser()
19+
.file("place.graphqls")
20+
.resolvers(PlaceQuery())
21+
.build().makeExecutableSchema()
22+
val gql = GraphQL.newGraphQL(schema).build()
23+
val result = gql.execute(ExecutionInput.newExecutionInput().query("query { places1 { id } places2 { id } }").build())
24+
assert(result.getData<Map<String, List<*>>>()["places1"]?.size == 3)
25+
assert(result.getData<Map<String, List<*>>>()["places2"]?.size == 2)
26+
}
27+
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package graphql.kickstart.tools.place
2+
3+
abstract class Review<T : Entity>(id: String? = null) : Entity(id) {
4+
5+
val rating: Int? = null
6+
val content: T? = null
7+
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package graphql.kickstart.tools.place
2+
3+
class Review1(id: String? = null) : Review<Place1>(id)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package graphql.kickstart.tools.place
2+
3+
class Review2(id: String? = null) : Review<Place2>(id)

0 commit comments

Comments
 (0)