|
1 | 1 | package graphql.kickstart.tools
|
2 | 2 |
|
3 | 3 | import graphql.kickstart.tools.resolver.FieldResolverError
|
| 4 | +import graphql.schema.GraphQLInterfaceType |
| 5 | +import graphql.schema.GraphQLObjectType |
4 | 6 | import org.junit.Before
|
5 | 7 | import org.junit.Rule
|
6 | 8 | import org.junit.Test
|
@@ -402,6 +404,81 @@ class SchemaParserTest {
|
402 | 404 | .makeExecutableSchema()
|
403 | 405 | }
|
404 | 406 |
|
| 407 | + @Test |
| 408 | + fun `interface implementing an interface should have non-empty interface list`() { |
| 409 | + val schema = SchemaParser.newParser() |
| 410 | + .schemaString( |
| 411 | + """ |
| 412 | + interface Trait { |
| 413 | + id: ID! |
| 414 | + } |
| 415 | + interface MammalTrait implements Trait { |
| 416 | + id: ID! |
| 417 | + } |
| 418 | + type PoodleTrait implements Trait & MammalTrait { |
| 419 | + id: ID! |
| 420 | + } |
| 421 | +
|
| 422 | + interface Animal { |
| 423 | + id: ID! |
| 424 | + traits: [Trait] |
| 425 | + } |
| 426 | + interface Dog implements Animal { |
| 427 | + id: ID! |
| 428 | + traits: [MammalTrait] |
| 429 | + } |
| 430 | + type Poodle implements Animal & Dog { |
| 431 | + id: ID! |
| 432 | + traits: [PoodleTrait] |
| 433 | + } |
| 434 | +
|
| 435 | + type Query { test: [Poodle] } |
| 436 | + """) |
| 437 | + .resolvers(MultiLevelInterfaceResolver()) |
| 438 | + .build() |
| 439 | + .makeExecutableSchema() |
| 440 | + val traitInterface = schema.getType("Trait") as GraphQLInterfaceType |
| 441 | + val animalInterface = schema.getType("Animal") as GraphQLInterfaceType |
| 442 | + val mammalTraitInterface = schema.getType("MammalTrait") as GraphQLInterfaceType |
| 443 | + val dogInterface = schema.getType("Dog") as GraphQLInterfaceType |
| 444 | + val poodleObject = schema.getType("Poodle") as GraphQLObjectType |
| 445 | + val poodleTraitObject = schema.getType("PoodleTrait") as GraphQLObjectType |
| 446 | + |
| 447 | + assert(poodleObject.interfaces.containsAll(listOf(dogInterface, animalInterface))) |
| 448 | + assert(poodleTraitObject.interfaces.containsAll(listOf(mammalTraitInterface, traitInterface))) |
| 449 | + assert(dogInterface.interfaces.contains(animalInterface)) |
| 450 | + assert(mammalTraitInterface.interfaces.contains(traitInterface)) |
| 451 | + assert(traitInterface.definition.implements.isEmpty()) |
| 452 | + assert(animalInterface.definition.implements.isEmpty()) |
| 453 | + } |
| 454 | + |
| 455 | + class MultiLevelInterfaceResolver : GraphQLQueryResolver { |
| 456 | + fun test(): List<Poodle> = listOf() |
| 457 | + |
| 458 | + interface Trait { |
| 459 | + var id: String |
| 460 | + } |
| 461 | + |
| 462 | + interface MammalTrait : Trait { |
| 463 | + override var id: String |
| 464 | + } |
| 465 | + |
| 466 | + interface PoodleTrait : MammalTrait { |
| 467 | + override var id: String |
| 468 | + } |
| 469 | + |
| 470 | + abstract class Animal<T : Trait> { |
| 471 | + var id: String? = null |
| 472 | + abstract var traits: List<T> |
| 473 | + } |
| 474 | + |
| 475 | + abstract class Dog<T : MammalTrait> : Animal<T>() { |
| 476 | + abstract override var traits: List<T> |
| 477 | + } |
| 478 | + |
| 479 | + class Poodle(override var traits: List<PoodleTrait>) : Dog<PoodleTrait>() |
| 480 | + } |
| 481 | + |
405 | 482 | enum class EnumType {
|
406 | 483 | TEST
|
407 | 484 | }
|
|
0 commit comments