Skip to content

Commit

Permalink
Cleaned up branch for PR graphql-java-kickstart#407
Browse files Browse the repository at this point in the history
  • Loading branch information
KammererTob committed Jul 12, 2020
1 parent 92deae1 commit 0e99154
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/groovy/graphql/kickstart/tools/BaseDevice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package graphql.kickstart.tools

interface BaseDevice {
val meta: BaseMeta?
}
3 changes: 3 additions & 0 deletions src/test/groovy/graphql/kickstart/tools/BaseMeta.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package graphql.kickstart.tools;

interface BaseMeta
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand Down Expand Up @@ -102,4 +114,16 @@ class FieldResolverScannerSpec extends Specification {
class GenericQuery implements GraphQLQueryResolver {
Connection<User> 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() }
}
}

0 comments on commit 0e99154

Please sign in to comment.