Skip to content

Commit 4c26e36

Browse files
author
Oryan M
committed
Merge branch 'master' into #434_GraphQlInputObjectType_at_runtime_wiring_on_nonnull_input
# Conflicts: # src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt
2 parents 420aabb + 7c0e22f commit 4c26e36

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-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/kotlin/graphql/kickstart/tools/SchemaParserTest.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphql.kickstart.tools
22

33
import graphql.kickstart.tools.resolver.FieldResolverError
4+
import graphql.schema.GraphQLInterfaceType
5+
import graphql.schema.GraphQLObjectType
46
import graphql.schema.GraphQLArgument
57
import graphql.schema.GraphQLInputObjectType
68
import graphql.schema.GraphQLNonNull
@@ -407,6 +409,81 @@ class SchemaParserTest {
407409
.makeExecutableSchema()
408410
}
409411

412+
@Test
413+
fun `interface implementing an interface should have non-empty interface list`() {
414+
val schema = SchemaParser.newParser()
415+
.schemaString(
416+
"""
417+
interface Trait {
418+
id: ID!
419+
}
420+
interface MammalTrait implements Trait {
421+
id: ID!
422+
}
423+
type PoodleTrait implements Trait & MammalTrait {
424+
id: ID!
425+
}
426+
427+
interface Animal {
428+
id: ID!
429+
traits: [Trait]
430+
}
431+
interface Dog implements Animal {
432+
id: ID!
433+
traits: [MammalTrait]
434+
}
435+
type Poodle implements Animal & Dog {
436+
id: ID!
437+
traits: [PoodleTrait]
438+
}
439+
440+
type Query { test: [Poodle] }
441+
""")
442+
.resolvers(MultiLevelInterfaceResolver())
443+
.build()
444+
.makeExecutableSchema()
445+
val traitInterface = schema.getType("Trait") as GraphQLInterfaceType
446+
val animalInterface = schema.getType("Animal") as GraphQLInterfaceType
447+
val mammalTraitInterface = schema.getType("MammalTrait") as GraphQLInterfaceType
448+
val dogInterface = schema.getType("Dog") as GraphQLInterfaceType
449+
val poodleObject = schema.getType("Poodle") as GraphQLObjectType
450+
val poodleTraitObject = schema.getType("PoodleTrait") as GraphQLObjectType
451+
452+
assert(poodleObject.interfaces.containsAll(listOf(dogInterface, animalInterface)))
453+
assert(poodleTraitObject.interfaces.containsAll(listOf(mammalTraitInterface, traitInterface)))
454+
assert(dogInterface.interfaces.contains(animalInterface))
455+
assert(mammalTraitInterface.interfaces.contains(traitInterface))
456+
assert(traitInterface.definition.implements.isEmpty())
457+
assert(animalInterface.definition.implements.isEmpty())
458+
}
459+
460+
class MultiLevelInterfaceResolver : GraphQLQueryResolver {
461+
fun test(): List<Poodle> = listOf()
462+
463+
interface Trait {
464+
var id: String
465+
}
466+
467+
interface MammalTrait : Trait {
468+
override var id: String
469+
}
470+
471+
interface PoodleTrait : MammalTrait {
472+
override var id: String
473+
}
474+
475+
abstract class Animal<T : Trait> {
476+
var id: String? = null
477+
abstract var traits: List<T>
478+
}
479+
480+
abstract class Dog<T : MammalTrait> : Animal<T>() {
481+
abstract override var traits: List<T>
482+
}
483+
484+
class Poodle(override var traits: List<PoodleTrait>) : Dog<PoodleTrait>()
485+
}
486+
410487
@Test
411488
fun `NonNull and nullable input arguments should resolve to GraphQLInputObjectType`() {
412489
val schema = SchemaParser.newParser()

0 commit comments

Comments
 (0)