@@ -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(" NoDogError" , NoDogError ::class )
2526 .build()
2627 .makeExecutableSchema()
2728
@@ -83,6 +84,9 @@ type Query {
8384 arrayItems: [Item!]!
8485
8586 throwsIllegalArgumentException: String
87+
88+ allDogs: [Dog!]!
89+ findSuitableDog(preferredColor: String!, minimumFluffiness: Int!): FindDogResult!
8690}
8791
8892type ExtendedType {
@@ -216,6 +220,18 @@ type Tag {
216220type ItemWithGenericProperties {
217221 keys: [String!]!
218222}
223+
224+ type Dog {
225+ name: String!
226+ color: String!
227+ fluffiness: Int!
228+ }
229+
230+ type NoDogError {
231+ msg: String
232+ }
233+
234+ union FindDogResult = Dog | NoDogError
219235"""
220236
221237val items = listOf (
@@ -314,6 +330,13 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
314330 fun throwsIllegalArgumentException (): String {
315331 throw IllegalArgumentException (" Expected" )
316332 }
333+
334+ fun allDogs (): List <Dog > = listOf (LabradorRetriever (" Hershey" , " chocolate" , 42 , 3.14159f ))
335+
336+ fun findSuitableDog (preferredColor : String , minimumFluffiness : Int ): Any =
337+ allDogs()
338+ .firstOrNull { it.color == preferredColor && it.fluffiness >= minimumFluffiness }
339+ ? : NoDogError (" No $preferredColor -colored dog found that is sufficiently fluffy" )
317340}
318341
319342class UnusedRootResolver : GraphQLQueryResolver
@@ -410,6 +433,15 @@ class MockPart(private val name: String, private val content: String) : Part {
410433 override fun delete () = throw IllegalArgumentException (" Not supported" )
411434}
412435
436+ interface Dog {
437+ val name: String
438+ val color: String
439+ val fluffiness: Int
440+ }
441+ interface Retriever : Dog { val speed: Float }
442+ class LabradorRetriever (override val name : String , override val color : String , override val fluffiness : Int , override val speed : Float ) : Retriever
443+ class NoDogError (val msg : String )
444+
413445val customScalarId = GraphQLScalarType .newScalar()
414446 .name(" ID" )
415447 .description(" Overrides built-in ID" )
0 commit comments