@@ -29,18 +29,6 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
29
29
30
30
private val allowedLastArgumentTypes = listOfNotNull(DataFetchingEnvironment ::class .java, options.contextClass)
31
31
32
- fun getAllMethods (type : JavaType ) =
33
- (type.unwrap().declaredNonProxyMethods.toList()
34
- + ClassUtils .getAllInterfaces(type.unwrap()).flatMap { it.methods.toList() }
35
- + ClassUtils .getAllSuperclasses(type.unwrap()).flatMap { it.methods.toList() })
36
- .asSequence()
37
- .filter { ! it.isSynthetic }
38
- .filter { ! Modifier .isPrivate(it.modifiers) }
39
- // discard any methods that are coming off the root of the class hierarchy
40
- // to avoid issues with duplicate method declarations
41
- .filter { it.declaringClass != Object ::class .java }
42
- .toList()
43
-
44
32
fun findFieldResolver (field : FieldDefinition , resolverInfo : ResolverInfo ): FieldResolver {
45
33
val searches = resolverInfo.getFieldSearches()
46
34
@@ -54,16 +42,6 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
54
42
return found.firstOrNull() ? : missingFieldResolver(field, searches, scanProperties)
55
43
}
56
44
57
- private fun missingFieldResolver (field : FieldDefinition , searches : List <Search >, scanProperties : Boolean ): FieldResolver {
58
- return if (options.allowUnimplementedResolvers) {
59
- log.warn(" Missing resolver for field: $field " )
60
-
61
- MissingFieldResolver (field, options)
62
- } else {
63
- throw FieldResolverError (getMissingFieldMessage(field, searches, scanProperties))
64
- }
65
- }
66
-
67
45
private fun findFieldResolver (field : FieldDefinition , search : Search , scanProperties : Boolean ): FieldResolver ? {
68
46
val method = findResolverMethod(field, search)
69
47
if (method != null ) {
@@ -84,15 +62,21 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
84
62
return null
85
63
}
86
64
87
- private fun isBoolean (type : GraphQLLangType ) = type.unwrap().let { it is TypeName && it.name == Scalars .GraphQLBoolean .name }
65
+ private fun missingFieldResolver (field : FieldDefinition , searches : List <Search >, scanProperties : Boolean ): FieldResolver {
66
+ return if (options.allowUnimplementedResolvers) {
67
+ log.warn(" Missing resolver for field: $field " )
68
+
69
+ MissingFieldResolver (field, options)
70
+ } else {
71
+ throw FieldResolverError (getMissingFieldMessage(field, searches, scanProperties))
72
+ }
73
+ }
88
74
89
75
private fun findResolverMethod (field : FieldDefinition , search : Search ): java.lang.reflect.Method ? {
90
76
val methods = getAllMethods(search.type)
91
77
val argumentCount = field.inputValueDefinitions.size + if (search.requiredFirstParameterType != null ) 1 else 0
92
78
val name = field.name
93
79
94
- val isBoolean = isBoolean(field.type)
95
-
96
80
// Check for the following one by one:
97
81
// 1. Method with exact field name
98
82
// 2. Method that returns a boolean with "is" style getter
@@ -101,14 +85,28 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
101
85
return methods.find {
102
86
it.name == name && verifyMethodArguments(it, argumentCount, search)
103
87
} ? : methods.find {
104
- (isBoolean && it.name == " is${name.capitalize()} " ) && verifyMethodArguments(it, argumentCount, search)
88
+ (isBoolean(field.type) && it.name == " is${name.capitalize()} " ) && verifyMethodArguments(it, argumentCount, search)
105
89
} ? : methods.find {
106
90
it.name == " get${name.capitalize()} " && verifyMethodArguments(it, argumentCount, search)
107
91
} ? : methods.find {
108
92
it.name == " getField${name.capitalize()} " && verifyMethodArguments(it, argumentCount, search)
109
93
}
110
94
}
111
95
96
+ private fun getAllMethods (type : JavaType ) =
97
+ (type.unwrap().declaredNonProxyMethods.toList()
98
+ + ClassUtils .getAllInterfaces(type.unwrap()).flatMap { it.methods.toList() }
99
+ + ClassUtils .getAllSuperclasses(type.unwrap()).flatMap { it.methods.toList() })
100
+ .asSequence()
101
+ .filter { ! it.isSynthetic }
102
+ .filter { ! Modifier .isPrivate(it.modifiers) }
103
+ // discard any methods that are coming off the root of the class hierarchy
104
+ // to avoid issues with duplicate method declarations
105
+ .filter { it.declaringClass != Object ::class .java }
106
+ .toList()
107
+
108
+ private fun isBoolean (type : GraphQLLangType ) = type.unwrap().let { it is TypeName && it.name == Scalars .GraphQLBoolean .name }
109
+
112
110
private fun verifyMethodArguments (method : java.lang.reflect.Method , requiredCount : Int , search : Search ): Boolean {
113
111
val appropriateFirstParameter = if (search.requiredFirstParameterType != null ) {
114
112
method.genericParameterTypes.firstOrNull()?.let {
0 commit comments