Skip to content

Commit 35962b5

Browse files
committed
Clean up logger instantiation
1 parent 92deae1 commit 35962b5

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ internal class SchemaClassScanner(
1919
private val scalars: CustomScalarMap,
2020
private val options: SchemaParserOptions
2121
) {
22-
companion object {
23-
val log = LoggerFactory.getLogger(SchemaClassScanner::class.java)!!
24-
}
22+
private val log = LoggerFactory.getLogger(javaClass)
2523

2624
private val rootInfo = RootTypeInfo.fromSchemaDefinitions(allDefinitions.filterIsInstance<SchemaDefinition>())
2725

@@ -153,9 +151,7 @@ internal class SchemaClassScanner(
153151
?: throw SchemaClassScannerError("Expected a user-defined GraphQL scalar type with name '${definition.name}' but found none!")
154152
GraphQLScalarType.newScalar()
155153
.name(provided.name)
156-
.description(
157-
if (definition.description != null) definition.description.content
158-
else SchemaParser.getDocumentation(definition) ?: provided.description)
154+
.description(definition.description?.content ?: getDocumentation(definition) ?: provided.description)
159155
.coercing(provided.coercing)
160156
.definition(definition)
161157
.build()

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package graphql.kickstart.tools
33
import graphql.Scalars
44
import graphql.introspection.Introspection
55
import graphql.kickstart.tools.directive.SchemaGeneratorDirectiveHelper
6+
import graphql.kickstart.tools.util.getDocumentation
67
import graphql.kickstart.tools.util.getExtendedFieldDefinitions
78
import graphql.kickstart.tools.util.unwrap
89
import graphql.language.*
@@ -24,17 +25,11 @@ class SchemaParser internal constructor(
2425
private val options: SchemaParserOptions,
2526
private val runtimeWiring: RuntimeWiring
2627
) {
27-
companion object {
28-
val log = LoggerFactory.getLogger(SchemaClassScanner::class.java)!!
29-
const val DEFAULT_DEPRECATION_MESSAGE = "No longer supported"
28+
private val log = LoggerFactory.getLogger(javaClass)
3029

30+
companion object {
3131
@JvmStatic
3232
fun newParser() = SchemaParserBuilder()
33-
34-
internal fun getDocumentation(node: AbstractNode<*>): String? = node.comments?.asSequence()
35-
?.filter { !it.content.startsWith("#") }
36-
?.joinToString("\n") { it.content.trimEnd() }
37-
?.trimIndent()
3833
}
3934

4035
private val dictionary = scanResult.dictionary
@@ -389,7 +384,7 @@ class SchemaParser internal constructor(
389384
}
390385
is TypeName -> {
391386
val scalarType = customScalars[typeDefinition.name]
392-
?: graphQLScalars[typeDefinition.name]
387+
?: GRAPHQL_SCALARS[typeDefinition.name]
393388
if (scalarType != null) {
394389
scalarType
395390
} else {
@@ -416,7 +411,7 @@ class SchemaParser internal constructor(
416411
}
417412
is TypeName -> {
418413
val scalarType = customScalars[typeDefinition.name]
419-
?: graphQLScalars[typeDefinition.name]
414+
?: GRAPHQL_SCALARS[typeDefinition.name]
420415
if (scalarType != null) {
421416
scalarType
422417
} else {
@@ -463,4 +458,6 @@ class SchemaParser internal constructor(
463458

464459
class SchemaError(message: String, cause: Throwable? = null) : RuntimeException(message, cause)
465460

466-
val graphQLScalars = ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS.associateBy { it.name }
461+
val GRAPHQL_SCALARS = ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS.associateBy { it.name }
462+
463+
const val DEFAULT_DEPRECATION_MESSAGE = "No longer supported"

src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@ import kotlin.reflect.jvm.kotlinFunction
2525
*/
2626
internal class FieldResolverScanner(val options: SchemaParserOptions) {
2727

28+
private val log = LoggerFactory.getLogger(javaClass)
29+
2830
private val allowedLastArgumentTypes = listOfNotNull(DataFetchingEnvironment::class.java, options.contextClass)
2931

30-
companion object {
31-
private val log = LoggerFactory.getLogger(FieldResolverScanner::class.java)
32-
33-
fun getAllMethods(type: JavaType) =
34-
(type.unwrap().declaredNonProxyMethods.toList()
35-
+ ClassUtils.getAllInterfaces(type.unwrap()).flatMap { it.methods.toList() }
36-
+ ClassUtils.getAllSuperclasses(type.unwrap()).flatMap { it.methods.toList() })
37-
.asSequence()
38-
.filter { !it.isSynthetic }
39-
.filter { !Modifier.isPrivate(it.modifiers) }
40-
// discard any methods that are coming off the root of the class hierarchy
41-
// to avoid issues with duplicate method declarations
42-
.filter { it.declaringClass != Object::class.java }
43-
.toList()
44-
}
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()
4543

4644
fun findFieldResolver(field: FieldDefinition, resolverInfo: ResolverInfo): FieldResolver {
4745
val searches = resolverInfo.getFieldSearches()

src/main/kotlin/graphql/kickstart/tools/util/Utils.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ internal val Class<*>.declaredNonProxyMethods: List<JavaMethod>
4949
}
5050
}
5151

52+
internal fun getDocumentation(node: AbstractNode<*>): String? = node.comments?.asSequence()
53+
?.filter { !it.content.startsWith("#") }
54+
?.joinToString("\n") { it.content.trimEnd() }
55+
?.trimIndent()
56+
5257
/**
5358
* Simple heuristic to check is a method is a trivial data fetcher.
5459
*

0 commit comments

Comments
 (0)