Skip to content

Commit

Permalink
graphql: upgrade to graphql-kotlin 6.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodongw committed Apr 29, 2023
1 parent 2dd9754 commit e7cd841
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protobuf = "3.22.3"
grpc = "1.54.1"
kotest = "5.6.1"
jackson = "2.15.0"
graphql-kotlin = "5.3.2"
graphql-kotlin = "6.4.0"
kotlin-logging = "3.0.5"
logback = "1.4.7"
slf4j = "2.0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@ package ws.leap.kert.graphql

import com.expediagroup.graphql.generator.execution.FunctionDataFetcher
import com.expediagroup.graphql.generator.execution.SimpleKotlinDataFetcherFactoryProvider
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import graphql.schema.DataFetcherFactory
import graphql.schema.DataFetchingEnvironment
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.reflect.KFunction
import kotlin.reflect.full.instanceParameter

open class ContextDataFetcherFactoryProvider(
private val objectMapper: ObjectMapper = jacksonObjectMapper()
) : SimpleKotlinDataFetcherFactoryProvider(objectMapper) {
open class ContextDataFetcherFactoryProvider : SimpleKotlinDataFetcherFactoryProvider() {

override fun functionDataFetcherFactory(target: Any?, kFunction: KFunction<*>) = DataFetcherFactory {
ContextFunctionDataFetcher(
target = target,
fn = kFunction,
objectMapper = objectMapper
fn = kFunction
)
}
}

class ContextFunctionDataFetcher(
private val target: Any?,
private val fn: KFunction<*>,
objectMapper: ObjectMapper = jacksonObjectMapper()
) : FunctionDataFetcher(target, fn, objectMapper) {
private val fn: KFunction<*>
) : FunctionDataFetcher(target, fn) {
override fun get(environment: DataFetchingEnvironment): Any? {
val instance: Any? = target ?: environment.getSource<Any?>()
val instanceParameter = fn.instanceParameter
Expand All @@ -38,8 +30,7 @@ class ContextFunctionDataFetcher(
.plus(instanceParameter to instance)

if (fn.isSuspend) {
val context: CoroutineContext = environment.graphQlContext.getOrDefault("coroutine-context", EmptyCoroutineContext)
runSuspendingFunction(parameterValues, context)
runSuspendingFunction(environment, parameterValues)
} else {
runBlockingFunction(parameterValues)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ fun main() {

runBlocking {
server.start()
println("Server started at http://localhost:8500/graphql")
}
}

0 comments on commit e7cd841

Please sign in to comment.