Skip to content

Commit 377b081

Browse files
author
Jógvan Olsen
committed
Added new exception for when failing to retreieve Kotlin Field
1 parent 21c3d60 commit 377b081

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
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.10.0
2+
version=0.10.1
33

44
# Dependencies
55
kotlin_version=1.3.50

kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/ParallelRequestExecutor.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.node.NullNode
2020
import com.fasterxml.jackson.databind.node.ObjectNode
2121
import kotlinx.coroutines.*
2222
import kotlin.coroutines.CoroutineContext
23+
import kotlin.reflect.KClass
2324
import kotlin.reflect.KProperty1
2425

2526

@@ -242,7 +243,15 @@ class ParallelRequestExecutor(val schema: DefaultSchema) : RequestExecutor, Coro
242243
if (include) {
243244
when (field) {
244245
is Field.Kotlin<*, *> -> {
245-
val rawValue = (field.kProperty as KProperty1<T, *>).get(parentValue)
246+
val rawValue = try {
247+
(field.kProperty as KProperty1<T, *>).get(parentValue)
248+
} catch (e: IllegalArgumentException) {
249+
throw ExecutionException(
250+
"Couldn't retrieve '${field.kProperty.name}' from class ${parentValue}}",
251+
node,
252+
e
253+
)
254+
}
246255
val value: Any? = field.transformation?.invoke(
247256
funName = field.name,
248257
receiver = rawValue,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.apurebase.kgraphql.integration
2+
3+
import com.apurebase.kgraphql.KGraphQL
4+
import org.junit.jupiter.api.Test
5+
6+
class GitHubIssuesBugTest {
7+
data class SearchHit(val spanData: Span)
8+
data class Tag(val key: String, val type: String, val value: String)
9+
data class LogPoint(val timestamp: Int, val fields: List<LogPointField>)
10+
data class LogPointField(val key: String, val value: String)
11+
data class Trace(val traceID: String, val spans: ArrayList<Span>) {
12+
companion object {
13+
fun fromSearchHits(traceID: String, hits: Array<SearchHit>): Trace {
14+
val spansArray = hits.map { Span.fromSearchHit(it) }.toTypedArray<Span>()
15+
return Trace(traceID, ArrayList(spansArray.sortedBy { it.startTime }))
16+
}
17+
}
18+
}
19+
data class Span(val traceID: String, val spanID: String, val parentSpanID: String?, val duration: Int, val startTime: Long, val operationName: String, val serviceName: String, val logs: ArrayList<LogPoint>?, val tags: ArrayList<Tag>?) {
20+
companion object {
21+
fun fromSearchHit(hit: SearchHit) = hit.spanData
22+
}
23+
}
24+
25+
@Test
26+
fun `issue-75 object is not of declaring class - full sample`() {
27+
val schema = KGraphQL.schema {
28+
configure {
29+
useDefaultPrettyPrinter = true
30+
}
31+
32+
query("findTrace") {
33+
resolver { traceID: String ->
34+
Trace(
35+
traceID = "646851f15cb2dad1",
36+
spans = arrayListOf(
37+
Span(
38+
traceID = "646851f15cb2dad1",
39+
spanID = "32b1133c2e838c56",
40+
parentSpanID = "646851f15cb2dad1",
41+
duration = 1701547,
42+
startTime = 1581974975400889,
43+
operationName = "banana",
44+
serviceName = "example1",
45+
logs = arrayListOf(),
46+
tags = arrayListOf(
47+
Tag(type = "string", value = "sample text", key = "_tracestep_stack"),
48+
Tag(type = "bool", value = "true", key = "_tracestep_main"),
49+
Tag(type = "string", value = "proto", key = "internal.span.format")
50+
)
51+
),
52+
Span(
53+
traceID = "646851f15cb2dad1",
54+
spanID = "7381e3787bb621db",
55+
parentSpanID = "32b1133c2e838c56",
56+
duration = 1000503,
57+
startTime = 1581974975401257,
58+
operationName = "start-req2",
59+
serviceName = "example2",
60+
logs = arrayListOf(),
61+
tags = arrayListOf(
62+
Tag(type = "string", value = "sample text", key = "_tracestep_stack"),
63+
Tag(type = "bool", value = "false", key = "_tracestep_main"),
64+
Tag(type = "string", value = "proto", key = "internal.span.format")
65+
)
66+
)
67+
)
68+
)
69+
}.withArgs {
70+
arg<String> { name = "traceID"}
71+
}
72+
}
73+
}
74+
75+
schema.executeBlocking("""
76+
query findTrace(${'$'}traceID: String!) {
77+
findTrace(traceID: ${'$'}traceID) {
78+
traceID
79+
spans {
80+
spanID
81+
tags {
82+
key
83+
value
84+
__typename
85+
}
86+
__typename
87+
}
88+
__typename
89+
}
90+
}
91+
""", "{\"traceID\": \"646851f15cb2dad1\"}").let(::println)
92+
}
93+
}

0 commit comments

Comments
 (0)