Skip to content

Commit 60123dc

Browse files
committed
add tests for unwrapGenericType to handle generics for deep hierarchy
1 parent a727ddb commit 60123dc

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-java-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)

src/test/resources/place.graphqls

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
type Query {
2+
places1: [Place1!]
3+
places2: [Place2!]
4+
}
5+
6+
interface Entity {
7+
id: ID!
8+
}
9+
10+
interface Place {
11+
name: String
12+
reviews: [Review!]
13+
}
14+
15+
interface OtherPlace {
16+
name: String
17+
other: String
18+
reviews: [Review!]
19+
}
20+
21+
type Place1 implements Entity, Place, OtherPlace {
22+
id: ID!
23+
name: String
24+
other: String
25+
reviews: [Review1!]
26+
}
27+
28+
type Place2 implements Entity, Place, OtherPlace {
29+
id: ID!
30+
name: String
31+
other: String
32+
reviews: [Review2!]
33+
}
34+
35+
interface Review {
36+
id: ID!
37+
rating: Int
38+
content: Entity
39+
}
40+
41+
type Review1 implements Review {
42+
id: ID!
43+
rating: Int
44+
content: Place1
45+
}
46+
47+
type Review2 implements Review {
48+
id: ID!
49+
rating: Int
50+
content: Place2
51+
}

0 commit comments

Comments
 (0)