Skip to content

Commit 2dfc9d5

Browse files
committed
When checking variable type, don't lose actual graphql type. Important when 2 graphql types are actually 1 single kotlin type.
1 parent 31dec6e commit 2dfc9d5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/main/kotlin/com/github/pgutkowski/kgraphql/request/Variables.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ data class Variables(
1818
/**
1919
* map and return object of requested class
2020
*/
21-
fun <T : Any> get(kClass: KClass<T>, kType: KType, key: String, transform: (value: String) -> Any?): T? {
21+
fun <T : Any> get(kClass: KClass<T>, kType: KType, typeName: String?, key: String, transform: (value: String) -> Any?): T? {
2222
val variable = variables?.find { key == it.name }
2323
?: throw IllegalArgumentException("Variable '$key' was not declared for this operation")
2424

2525
val isIterable = kClass.isIterable()
2626

27-
validateVariable(typeDefinitionProvider.typeReference(kType), variable)
27+
validateVariable(typeDefinitionProvider.typeReference(kType), typeName, variable)
2828

2929
var value = variablesJson.get(kClass, kType, key.substring(1))
3030
if(value == null && variable.defaultValue != null){
@@ -57,9 +57,9 @@ data class Variables(
5757
}
5858
}
5959

60-
fun validateVariable(expectedType: TypeReference, variable: OperationVariable){
60+
fun validateVariable(expectedType: TypeReference, expectedTypeName: String?, variable: OperationVariable){
6161
val variableType = variable.type
62-
val invalidName = expectedType.name != variableType.name
62+
val invalidName = (expectedTypeName ?: expectedType.name) != variableType.name
6363
val invalidIsList = expectedType.isList != variableType.isList
6464
val invalidNullability = !expectedType.isNullable && variableType.isNullable && variable.defaultValue == null
6565
val invalidElementNullability = !expectedType.isElementNullable && variableType.isElementNullable

src/main/kotlin/com/github/pgutkowski/kgraphql/schema/execution/ArgumentTransformer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ open class ArgumentTransformer(val schema : DefaultSchema) {
1616

1717
fun transformValue(type: Type, value: String, variables: Variables) : Any? {
1818
val kType = type.toKType()
19+
val typeName = type.unwrapped().name
1920

2021
return when {
2122
value.startsWith("$") -> {
2223
variables.get (
23-
kType.jvmErasure, kType, value, { subValue -> transformValue(type, subValue, variables) }
24+
kType.jvmErasure, kType, typeName, value, { subValue -> transformValue(type, subValue, variables) }
2425
)
2526
}
2627
value == "null" && type.isNullable() -> null

0 commit comments

Comments
 (0)