Skip to content

Commit 8bbb7bc

Browse files
committed
interface type can have non-empty interface lists
1 parent 0b2a3a5 commit 8bbb7bc

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ class SchemaParser internal constructor(
234234
builder.field { field -> createField(field, fieldDefinition, inputObjects) }
235235
}
236236

237+
interfaceDefinition.implements.forEach { implementsDefinition ->
238+
val interfaceName = (implementsDefinition as TypeName).name
239+
builder.withInterface(GraphQLTypeReference(interfaceName))
240+
}
241+
237242
return schemaGeneratorDirectiveHelper.onInterface(builder.build(), schemaDirectiveParameters)
238243
}
239244

src/test/groovy/graphql/kickstart/tools/SchemaParserSpec.groovy

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package graphql.kickstart.tools
22

33
import graphql.kickstart.tools.resolver.FieldResolverError
44
import graphql.language.SourceLocation
5+
import graphql.schema.GraphQLInterfaceType
56
import graphql.schema.GraphQLSchema
67
import org.springframework.aop.framework.ProxyFactory
78
import spock.lang.Specification
@@ -418,6 +419,71 @@ class SchemaParserSpec extends Specification {
418419
noExceptionThrown()
419420
}
420421

422+
def "interface implementing an interface should have non-empty interface list"() {
423+
when:
424+
GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
425+
interface Trait {
426+
id: ID!
427+
}
428+
interface MammalTrait implements Trait {
429+
id: ID!
430+
}
431+
type PoodleTrait implements Trait & MammalTrait {
432+
id: ID!
433+
}
434+
435+
interface Animal {
436+
id: ID!
437+
traits: [Trait]
438+
}
439+
interface Dog implements Animal {
440+
id: ID!
441+
traits: [MammalTrait]
442+
}
443+
type Poodle implements Animal & Dog {
444+
id: ID!
445+
traits: [PoodleTrait]
446+
}
447+
448+
type Query { test: [Poodle] }'''.stripIndent())
449+
.resolvers(new GraphQLQueryResolver() {
450+
static abstract class Trait {
451+
String id;
452+
}
453+
454+
static abstract class MammalTrait extends Trait {
455+
String id;
456+
}
457+
458+
static class PoodleTrait extends MammalTrait {
459+
String id;
460+
}
461+
462+
static abstract class Animal {
463+
String id;
464+
abstract List<Trait> traits;
465+
}
466+
467+
static abstract class Dog extends Animal {
468+
abstract List<MammalTrait> traits;
469+
}
470+
471+
static class Poodle extends Dog {
472+
List<PoodleTrait> traits;
473+
}
474+
475+
List<Poodle> test() { return new ArrayList<Poodle>(); }
476+
})
477+
.build()
478+
.makeExecutableSchema()
479+
GraphQLInterfaceType traitInterface = schema.getType("MammalTrait") as GraphQLInterfaceType
480+
GraphQLInterfaceType dogInterface = schema.getType("Dog") as GraphQLInterfaceType
481+
482+
then:
483+
!traitInterface.interfaces.empty
484+
!dogInterface.interfaces.empty
485+
}
486+
421487
enum EnumType {
422488
TEST
423489
}

0 commit comments

Comments
 (0)