@@ -22,7 +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 )
25+ .dictionary(" NoDogError " , NoDogError ::class )
2626 .build()
2727 .makeExecutableSchema()
2828
@@ -85,8 +85,8 @@ type Query {
8585
8686 throwsIllegalArgumentException: String
8787
88- allBars : [Bar !]!
89- findAvailableBar(persons: Int!): BarResult !
88+ allDogs : [Dog !]!
89+ findSuitableDog(preferredColor: String!, minimumFluffiness: Int!): FindDogResult !
9090}
9191
9292type ExtendedType {
@@ -221,15 +221,17 @@ type ItemWithGenericProperties {
221221 keys: [String!]!
222222}
223223
224- type Bar {
225- name: String
224+ type Dog {
225+ name: String!
226+ color: String!
227+ fluffiness: Int!
226228}
227229
228- type OutOfBeerError {
230+ type NoDogError {
229231 msg: String
230232}
231233
232- union BarResult = Bar | OutOfBeerError
234+ union FindDogResult = Dog | NoDogError
233235"""
234236
235237val items = listOf (
@@ -329,15 +331,12 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
329331 throw IllegalArgumentException (" Expected" )
330332 }
331333
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- }
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" )
341340}
342341
343342class UnusedRootResolver : GraphQLQueryResolver
@@ -434,10 +433,14 @@ class MockPart(private val name: String, private val content: String) : Part {
434433 override fun delete () = throw IllegalArgumentException (" Not supported" )
435434}
436435
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 )
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 )
441444
442445val customScalarId = GraphQLScalarType .newScalar()
443446 .name(" ID" )
0 commit comments