@@ -3,20 +3,19 @@ package com.apurebase.kgraphql.schema.execution
3
3
import com.apurebase.kgraphql.Context
4
4
import com.apurebase.kgraphql.InvalidInputValueException
5
5
import com.apurebase.kgraphql.request.Variables
6
- import com.apurebase.kgraphql.schema.DefaultSchema
7
6
import com.apurebase.kgraphql.schema.introspection.TypeKind
7
+ import com.apurebase.kgraphql.schema.introspection.__Schema
8
8
import com.apurebase.kgraphql.schema.introspection.typeReference
9
9
import com.apurebase.kgraphql.schema.model.ast.ArgumentNodes
10
10
import com.apurebase.kgraphql.schema.model.ast.ValueNode
11
11
import com.apurebase.kgraphql.schema.model.ast.ValueNode.ObjectValueNode
12
12
import com.apurebase.kgraphql.schema.scalar.deserializeScalar
13
13
import com.apurebase.kgraphql.schema.structure.InputValue
14
14
import com.apurebase.kgraphql.schema.structure.Type
15
- import kotlin.reflect.KType
16
15
import kotlin.reflect.full.primaryConstructor
17
16
import kotlin.reflect.jvm.jvmErasure
18
17
19
- open class ArgumentTransformer (val schema : DefaultSchema ) {
18
+ open class ArgumentTransformer (val schema : __Schema ) {
20
19
21
20
fun transformArguments (
22
21
funName : String ,
@@ -120,7 +119,12 @@ open class ArgumentTransformer(val schema: DefaultSchema) {
120
119
value
121
120
)
122
121
123
- params.getValue(valueField.name.value) to transformValue(paramType, valueField.value, variables, coerceSingleValueAsList)
122
+ params.getValue(valueField.name.value) to transformValue(
123
+ paramType,
124
+ valueField.value,
125
+ variables,
126
+ coerceSingleValueAsList
127
+ )
124
128
}
125
129
126
130
val missingNonOptionalInputs = params.values.filter { ! it.isOptional && ! valueMap.containsKey(it) }
@@ -157,13 +161,11 @@ open class ArgumentTransformer(val schema: DefaultSchema) {
157
161
}
158
162
}
159
163
160
- else -> transformString(value, kType )
164
+ else -> transformString(value, type.unwrapped() )
161
165
}
162
166
}
163
167
164
- private fun transformString (value : ValueNode , kType : KType ): Any {
165
-
166
- val kClass = kType.jvmErasure
168
+ private fun transformString (value : ValueNode , type : Type ): Any {
167
169
168
170
fun throwInvalidEnumValue (enumType : Type .Enum <* >) {
169
171
throw InvalidInputValueException (
@@ -172,19 +174,19 @@ open class ArgumentTransformer(val schema: DefaultSchema) {
172
174
)
173
175
}
174
176
175
- schema.model.enums[kClass] ?.let { enumType ->
177
+ (type as ? Type . Enum < * >) ?.let { enumType ->
176
178
return if (value is ValueNode .EnumValueNode ) {
177
- enumType.values.find { it.name == value.value }?.value ? : throwInvalidEnumValue(enumType)
179
+ enumType.values.firstOrNull { it.name == value.value }?.value ? : throwInvalidEnumValue(enumType)
178
180
} else {
179
181
throw InvalidInputValueException (
180
182
" String literal '${value.valueNodeName} ' is invalid value for enum type ${enumType.name} " ,
181
183
value
182
184
)
183
185
}
184
- } ? : schema.model.scalars[kClass] ?.let { scalarType ->
186
+ } ? : (type as ? Type . Scalar < * >) ?.let { scalarType ->
185
187
return deserializeScalar(scalarType, value)
186
188
} ? : throw InvalidInputValueException (
187
- " Invalid argument value '${value.valueNodeName} ' for type ${schema.model.inputTypes[kClass]? .name} " ,
189
+ " Invalid argument value '${value.valueNodeName} ' for type ${type .name} " ,
188
190
value
189
191
)
190
192
}
0 commit comments