Skip to content

Commit 7c122dd

Browse files
authored
Merge pull request #157 from ESchouten/input-type
InputValue KType
2 parents 9a4b066 + 68d6c23 commit 7c122dd

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# KGraphQL version
2-
version=0.17.11
2+
version=0.17.12-SNAPSHOT
33

44
# Dependencies
55
coroutine_version=1.5.0

kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/dsl/types/InputValueDSL.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package com.apurebase.kgraphql.schema.dsl.types
33
import com.apurebase.kgraphql.schema.dsl.DepreciableItemDSL
44
import com.apurebase.kgraphql.schema.model.InputValueDef
55
import kotlin.reflect.KClass
6+
import kotlin.reflect.KType
67

78

8-
class InputValueDSL<T : Any>(val kClass: KClass<T>) : DepreciableItemDSL() {
9+
class InputValueDSL<T : Any>(val kClass: KClass<T>, val kType: KType? = null) : DepreciableItemDSL() {
910

1011
lateinit var name : String
1112

@@ -17,6 +18,7 @@ class InputValueDSL<T : Any>(val kClass: KClass<T>) : DepreciableItemDSL() {
1718
defaultValue = defaultValue,
1819
isDeprecated = isDeprecated,
1920
description = description,
20-
deprecationReason = deprecationReason
21+
deprecationReason = deprecationReason,
22+
kType = kType
2123
)
22-
}
24+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.apurebase.kgraphql.schema.dsl.types
22

33
import kotlin.reflect.KClass
4+
import kotlin.reflect.KType
5+
import kotlin.reflect.typeOf
46

57

68
class InputValuesDSL {
79

810
val inputValues = mutableListOf<InputValueDSL<*>>()
911

10-
11-
fun <T : Any> arg(kClass: KClass<T>, block : InputValueDSL<T>.() -> Unit){
12-
inputValues.add(InputValueDSL(kClass).apply(block))
12+
fun <T : Any> arg(kClass: KClass<T>, kType: KType? = null, block : InputValueDSL<T>.() -> Unit){
13+
inputValues.add(InputValueDSL(kClass, kType).apply(block))
1314
}
1415

16+
@OptIn(ExperimentalStdlibApi::class)
1517
inline fun <reified T : Any> arg(noinline block : InputValueDSL<T>.() -> Unit){
16-
arg(T::class, block)
18+
arg(T::class, typeOf<T>(), block)
1719
}
1820

19-
}
21+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.apurebase.kgraphql.schema.model
22

33
import kotlin.reflect.KClass
4+
import kotlin.reflect.KType
45

56

67
class InputValueDef<T : Any>(
@@ -9,5 +10,6 @@ class InputValueDef<T : Any>(
910
val defaultValue : T? = null,
1011
override val isDeprecated: Boolean = false,
1112
override val description: String? = null,
12-
override val deprecationReason: String? = null
13-
) : DescribedDef, Depreciable
13+
override val deprecationReason: String? = null,
14+
val kType : KType? = null
15+
) : DescribedDef, Depreciable

kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/structure/SchemaCompilation.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ class SchemaCompilation(
332332
}
333333

334334
return operation.argumentsDescriptor.map { (name, kType) ->
335-
val kqlInput = inputValues.find { it.name == name } ?: InputValueDef(kType.jvmErasure, name)
336-
val inputType = handlePossiblyWrappedType(kType, TypeCategory.INPUT)
335+
val inputValue = inputValues.find { it.name == name }
336+
val kqlInput = inputValue ?: InputValueDef(kType.jvmErasure, name)
337+
val inputType = handlePossiblyWrappedType(inputValue?.kType ?: kType, TypeCategory.INPUT)
337338
InputValue(kqlInput, inputType)
338339
}
339340
}

0 commit comments

Comments
 (0)