diff --git a/src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt b/src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt index 0ce02dab..537688d4 100644 --- a/src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt +++ b/src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt @@ -40,6 +40,7 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) { // discard any methods that are coming off the root of the class hierarchy // to avoid issues with duplicate method declarations .filter { it.declaringClass != Object::class.java } + .sortedBy { it.returnType.isInterface } .toList() } diff --git a/src/test/groovy/graphql/kickstart/tools/BaseDevice.kt b/src/test/groovy/graphql/kickstart/tools/BaseDevice.kt new file mode 100644 index 00000000..749c4301 --- /dev/null +++ b/src/test/groovy/graphql/kickstart/tools/BaseDevice.kt @@ -0,0 +1,5 @@ +package graphql.kickstart.tools + +interface BaseDevice { + val meta: BaseMeta? +} \ No newline at end of file diff --git a/src/test/groovy/graphql/kickstart/tools/BaseMeta.kt b/src/test/groovy/graphql/kickstart/tools/BaseMeta.kt new file mode 100644 index 00000000..e99a2e56 --- /dev/null +++ b/src/test/groovy/graphql/kickstart/tools/BaseMeta.kt @@ -0,0 +1,3 @@ +package graphql.kickstart.tools; + +interface BaseMeta \ No newline at end of file diff --git a/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy b/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy index ee3747d4..b9be6b80 100644 --- a/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy +++ b/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy @@ -75,6 +75,18 @@ class FieldResolverScannerSpec extends Specification { users instanceof MethodFieldResolver } + def "scanner prefers concrete resolver"() { + setup: + def resolver = new DataClassResolverInfo(Device.class) + + when: + def meta = scanner.findFieldResolver(new FieldDefinition("meta", new TypeName("Meta")), resolver) + + then: + meta instanceof MethodFieldResolver + !((MethodFieldResolver) meta).getMethod().getReturnType().isInterface() + } + class RootQuery1 implements GraphQLQueryResolver { def field1() {} } @@ -102,4 +114,16 @@ class FieldResolverScannerSpec extends Specification { class GenericQuery implements GraphQLQueryResolver { Connection getUsers() {} } -} + + abstract class ParentDevice implements BaseDevice { + ConcreteMeta getMeta() { return this.meta; } + } + + class ConcreteMeta implements BaseMeta {} + + class Device extends ParentDevice implements BaseDevice {} + + class InterfaceQuery implements GraphQLQueryResolver { + Device getDevice() { return new Device() } + } +} \ No newline at end of file