@@ -22,7 +22,7 @@ fun createSchema() = SchemaParser.newParser()
22
22
.dictionary(" ThirdItem" , ThirdItem ::class )
23
23
.dictionary(" ComplexMapItem" , ComplexMapItem ::class )
24
24
.dictionary(" NestedComplexMapItem" , NestedComplexMapItem ::class )
25
- .dictionary(" OutOfBeerError " , OutOfBeerError ::class )
25
+ .dictionary(" NoDogError " , NoDogError ::class )
26
26
.build()
27
27
.makeExecutableSchema()
28
28
@@ -85,8 +85,8 @@ type Query {
85
85
86
86
throwsIllegalArgumentException: String
87
87
88
- allBars : [Bar !]!
89
- findAvailableBar(persons: Int!): BarResult !
88
+ allDogs : [Dog !]!
89
+ findSuitableDog(preferredColor: String!, minimumFluffiness: Int!): FindDogResult !
90
90
}
91
91
92
92
type ExtendedType {
@@ -221,15 +221,17 @@ type ItemWithGenericProperties {
221
221
keys: [String!]!
222
222
}
223
223
224
- type Bar {
225
- name: String
224
+ type Dog {
225
+ name: String!
226
+ color: String!
227
+ fluffiness: Int!
226
228
}
227
229
228
- type OutOfBeerError {
230
+ type NoDogError {
229
231
msg: String
230
232
}
231
233
232
- union BarResult = Bar | OutOfBeerError
234
+ union FindDogResult = Dog | NoDogError
233
235
"""
234
236
235
237
val items = listOf (
@@ -329,15 +331,12 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
329
331
throw IllegalArgumentException (" Expected" )
330
332
}
331
333
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" )
341
340
}
342
341
343
342
class UnusedRootResolver : GraphQLQueryResolver
@@ -434,10 +433,14 @@ class MockPart(private val name: String, private val content: String) : Part {
434
433
override fun delete () = throw IllegalArgumentException (" Not supported" )
435
434
}
436
435
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 )
441
444
442
445
val customScalarId = GraphQLScalarType .newScalar()
443
446
.name(" ID" )
0 commit comments