Skip to content

Commit eeb11bb

Browse files
committed
Test case for #558
1 parent 7690168 commit eeb11bb

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fun createSchema() = SchemaParser.newParser()
2222
.dictionary("ThirdItem", ThirdItem::class)
2323
.dictionary("ComplexMapItem", ComplexMapItem::class)
2424
.dictionary("NestedComplexMapItem", NestedComplexMapItem::class)
25+
.dictionary("OutOfBeerError", OutOfBeerError::class)
2526
.build()
2627
.makeExecutableSchema()
2728

@@ -83,6 +84,9 @@ type Query {
8384
arrayItems: [Item!]!
8485
8586
throwsIllegalArgumentException: String
87+
88+
allBars: [Bar!]!
89+
findAvailableBar(persons: Int!): BarResult!
8690
}
8791
8892
type ExtendedType {
@@ -216,6 +220,16 @@ type Tag {
216220
type ItemWithGenericProperties {
217221
keys: [String!]!
218222
}
223+
224+
type Bar {
225+
name: String
226+
}
227+
228+
type OutOfBeerError {
229+
msg: String
230+
}
231+
232+
union BarResult = Bar | OutOfBeerError
219233
"""
220234

221235
val items = listOf(
@@ -314,6 +328,16 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
314328
fun throwsIllegalArgumentException(): String {
315329
throw IllegalArgumentException("Expected")
316330
}
331+
332+
fun allBars(): List<Bar> {
333+
return listOf(BarEntityImpl("123", "Bar Name"))
334+
}
335+
fun findAvailableBar(persons: Int): Any {
336+
if (persons < 56)
337+
return BarEntityImpl("123", "Bar Name");
338+
else
339+
return OutOfBeerError("No room for $persons persons")
340+
}
317341
}
318342

319343
class UnusedRootResolver : GraphQLQueryResolver
@@ -410,6 +434,11 @@ class MockPart(private val name: String, private val content: String) : Part {
410434
override fun delete() = throw IllegalArgumentException("Not supported")
411435
}
412436

437+
interface Bar { val name: String }
438+
interface BarEntity : Bar { val id: String}
439+
class BarEntityImpl(override val id: String, override val name: String) : BarEntity
440+
class OutOfBeerError(val msg: String)
441+
413442
val customScalarId = GraphQLScalarType.newScalar()
414443
.name("ID")
415444
.description("Overrides built-in ID")

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ class EndToEndTest {
178178
assertNotNull(data["itemByUUID"])
179179
}
180180

181+
@Test
182+
fun `generated schema should handle union types with deep hierarchy`() {
183+
val data = assertNoGraphQlErrors(gql) {
184+
"""
185+
{
186+
findAvailableBar(persons: 42) {
187+
... on Bar { name }
188+
... on OutOfBeerError { msg }
189+
}
190+
}
191+
"""
192+
}
193+
194+
assertNotNull(data["findAvailableBar"])
195+
}
196+
181197
@Test
182198
fun `generated schema should handle non nullable scalar types`() {
183199
val fileParts = listOf(MockPart("test.doc", "Hello"), MockPart("test.doc", "World"))

0 commit comments

Comments
 (0)