Skip to content

Make compatible with other JVM Locales as for example turkish. #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.lang.reflect.Type
import java.util.Locale
import kotlin.reflect.full.valueParameters
import kotlin.reflect.jvm.javaType
import kotlin.reflect.jvm.kotlinFunction
Expand Down Expand Up @@ -86,11 +87,11 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
return methods.find {
it.name == name && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
(isBoolean(field.type) && it.name == "is${name.capitalize()}") && verifyMethodArguments(it, argumentCount, search)
(isBoolean(field.type) && it.name == "is${name.capitalize(Locale.ROOT)}") && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "get${name.capitalize()}" && verifyMethodArguments(it, argumentCount, search)
it.name == "get${name.capitalize(Locale.ROOT)}" && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "getField${name.capitalize()}" && verifyMethodArguments(it, argumentCount, search)
it.name == "getField${name.capitalize(Locale.ROOT)}" && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "get${name.snakeToCamelCase()}" && verifyMethodArguments(it, argumentCount, search)
}
Expand Down Expand Up @@ -179,9 +180,9 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {

signatures.add("${baseType.name}.${field.name}($argString)")
if (isBoolean) {
signatures.add("${baseType.name}.is${field.name.capitalize()}($argString)")
signatures.add("${baseType.name}.is${field.name.capitalize(Locale.ROOT)}($argString)")
}
signatures.add("${baseType.name}.get${field.name.capitalize()}($argString)")
signatures.add("${baseType.name}.get${field.name.capitalize(Locale.ROOT)}($argString)")
if (scannedProperties) {
signatures.add("${baseType.name}.${field.name}")
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/graphql/kickstart/tools/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.Dispatchers
import java.lang.reflect.Method
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Proxy
import java.util.Locale

/**
* @author Andrew Potter
Expand Down Expand Up @@ -72,5 +73,5 @@ private fun isBooleanGetter(method: Method) = (method.name.startsWith("is")
&& (method.returnType == java.lang.Boolean::class.java)
|| method.returnType == Boolean::class.java)

internal fun String.snakeToCamelCase(): String = split("_").joinToString(separator = "") { it.capitalize() }
internal fun String.snakeToCamelCase(): String = split("_").joinToString(separator = "") { it.capitalize(Locale.ROOT) }

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class FieldResolverScannerTest {
assertEquals((meta as MethodFieldResolver).method.returnType, HullType::class.java)
}

@Test
fun `scanner finds field resolver method using capitalize field_name`() {
val resolver = RootResolverInfo(listOf(CapitalizeQuery()), options)

val meta = scanner.findFieldResolver(FieldDefinition("id", TypeName("HullType")), resolver)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make sure the test will fail on all machines by setting the default locale to Turkish Locale.forLanguageTag("tr-TR") and resetting it back to default at the end.
And add a comment to explain why we do that please.


assert(meta is MethodFieldResolver)
assertEquals((meta as MethodFieldResolver).method.returnType, HullType::class.java)
}

class RootQuery1 : GraphQLQueryResolver {
fun field1() {}
}
Expand All @@ -97,6 +107,10 @@ class FieldResolverScannerTest {
fun getHullType(): HullType = HullType()
}

class CapitalizeQuery : GraphQLQueryResolver {
fun getId(): HullType = HullType()
}

class HullType

open class ParentPropertyQuery {
Expand Down