Skip to content

Commit e55fd82

Browse files
committed
Simplify and rename PlaceTest.kt
1 parent 60123dc commit e55fd82

File tree

13 files changed

+63
-70
lines changed

13 files changed

+63
-70
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.3-SNAPSHOT</version>
7+
<version>5.7.2-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>GraphQL Java Tools</name>

src/main/kotlin/graphql/kickstart/tools/GenericType.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ internal open class GenericType(protected val mostSpecificType: JavaType, protec
124124
private fun unwrapGenericType(declaringType: ParameterizedType, type: TypeVariable<*>): JavaType {
125125
val rawClass = getRawClass(mostSpecificType)
126126
val arguments = TypeUtils.determineTypeArguments(rawClass, declaringType)
127-
val t = arguments.filter { it.key.name == type.name }.values.firstOrNull()
127+
val matchingType = arguments
128+
.filter { it.key.name == type.name }
129+
.values
130+
.firstOrNull()
128131
?: error("No type variable found for: ${TypeUtils.toLongString(type)}")
129-
return unwrapGenericType(t)
132+
133+
return unwrapGenericType(matchingType)
130134
}
131135

132136
private fun replaceTypeVariable(type: JavaType): JavaType {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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)

src/test/kotlin/graphql/kickstart/tools/UtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UtilsTest {
2424
}
2525

2626
@Test
27-
fun `isTrivialDataFetcher`() {
27+
fun isTrivialDataFetcher() {
2828
val clazz = Bean::class.java
2929

3030
Assert.assertTrue(isTrivialDataFetcher(clazz.getMethod("getterValid")))

src/test/kotlin/graphql/kickstart/tools/place/Entity.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/OtherPlace.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Place.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Place1.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Place2.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/PlaceTest.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Review.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Review1.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/kotlin/graphql/kickstart/tools/place/Review2.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)