Skip to content
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

Make compatible with other JVM Locales #565

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -86,11 +86,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.replaceFirstChar(Char::titlecase)}") && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "get${name.capitalize()}" && verifyMethodArguments(it, argumentCount, search)
it.name == "get${name.replaceFirstChar(Char::titlecase)}" && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "getField${name.capitalize()}" && verifyMethodArguments(it, argumentCount, search)
it.name == "getField${name.replaceFirstChar(Char::titlecase)}" && verifyMethodArguments(it, argumentCount, search)
} ?: methods.find {
it.name == "get${name.snakeToCamelCase()}" && verifyMethodArguments(it, argumentCount, search)
}
Expand Down Expand Up @@ -179,9 +179,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.replaceFirstChar(Char::titlecase)}($argString)")
}
signatures.add("${baseType.name}.get${field.name.capitalize()}($argString)")
signatures.add("${baseType.name}.get${field.name.replaceFirstChar(Char::titlecase)}($argString)")
if (scannedProperties) {
signatures.add("${baseType.name}.${field.name}")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/graphql/kickstart/tools/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,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.replaceFirstChar(Char::titlecase) }

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import graphql.relay.Connection
import graphql.relay.DefaultConnection
import graphql.relay.DefaultPageInfo
import org.junit.Test
import java.util.*

class FieldResolverScannerTest {

Expand Down Expand Up @@ -81,6 +82,20 @@ class FieldResolverScannerTest {
assertEquals((meta as MethodFieldResolver).method.returnType, HullType::class.java)
}

@Test
fun `scanner finds field resolver method using capitalize field_name in different locale`() {
val default = Locale.getDefault()
Locale.setDefault(Locale.forLanguageTag("tr-TR"))

val resolverInfo = RootResolverInfo(listOf(CapitalizeQuery()), options)
val fieldResolver = scanner.findFieldResolver(FieldDefinition("id", TypeName("HullType")), resolverInfo)

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

Locale.setDefault(default)
}

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

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

class HullType

open class ParentPropertyQuery {
Expand Down