Skip to content

Interface type can have non-empty interface lists #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ class SchemaParser internal constructor(
builder.field { field -> createField(field, fieldDefinition, inputObjects) }
}

interfaceDefinition.implements.forEach { implementsDefinition ->
val interfaceName = (implementsDefinition as TypeName).name
builder.withInterface(GraphQLTypeReference(interfaceName))
}

return schemaGeneratorDirectiveHelper.onInterface(builder.build(), schemaDirectiveParameters)
}

Expand Down
76 changes: 76 additions & 0 deletions src/test/groovy/graphql/kickstart/tools/SchemaParserSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package graphql.kickstart.tools

import graphql.kickstart.tools.resolver.FieldResolverError
import graphql.language.SourceLocation
import graphql.schema.GraphQLInterfaceType
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
import org.springframework.aop.framework.ProxyFactory
import spock.lang.Specification
Expand Down Expand Up @@ -418,6 +420,80 @@ class SchemaParserSpec extends Specification {
noExceptionThrown()
}

def "interface implementing an interface should have non-empty interface list"() {
when:
GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
interface Trait {
id: ID!
}
interface MammalTrait implements Trait {
id: ID!
}
type PoodleTrait implements Trait & MammalTrait {
id: ID!
}

interface Animal {
id: ID!
traits: [Trait]
}
interface Dog implements Animal {
id: ID!
traits: [MammalTrait]
}
type Poodle implements Animal & Dog {
id: ID!
traits: [PoodleTrait]
}

type Query { test: [Poodle] }
'''.stripIndent())
.resolvers(new GraphQLQueryResolver() {
static abstract class Trait {
String id;
}

static abstract class MammalTrait extends Trait {
String id;
}

static class PoodleTrait extends MammalTrait {
String id;
}

static abstract class Animal {
String id;
abstract List<Trait> traits;
}

static abstract class Dog extends Animal {
abstract List<MammalTrait> traits;
}

static class Poodle extends Dog {
List<PoodleTrait> traits;
}

List<Poodle> test() { return new ArrayList<Poodle>(); }
})
.build()
.makeExecutableSchema()
GraphQLInterfaceType traitInterface = schema.getType("Trait") as GraphQLInterfaceType
GraphQLInterfaceType animalInterface = schema.getType("Animal") as GraphQLInterfaceType
GraphQLInterfaceType mammalTraitInterface = schema.getType("MammalTrait") as GraphQLInterfaceType
GraphQLInterfaceType dogInterface = schema.getType("Dog") as GraphQLInterfaceType
GraphQLObjectType poodleObject = schema.getType("Poodle") as GraphQLObjectType
GraphQLObjectType poodleTraitObject = schema.getType("PoodleTrait") as GraphQLObjectType

then:
poodleObject.interfaces.containsAll([dogInterface, animalInterface])
poodleTraitObject.interfaces.containsAll([mammalTraitInterface, traitInterface])
dogInterface.interfaces.contains(animalInterface)
mammalTraitInterface.interfaces.contains(traitInterface)
traitInterface.interfaces.empty
animalInterface.interfaces.empty
}

enum EnumType {
TEST
}
Expand Down