From d05d13e2e02d163e74399b24326e7dfeb2bfd354 Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Thu, 15 Aug 2024 10:11:26 -0700 Subject: [PATCH] 6.x.x revert context switching (#2030) Co-authored-by: Samuel Vazquez --- .../graphql/server/execution/GraphQLServer.kt | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt b/servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt index 05397f14f2..c5831e616e 100644 --- a/servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt +++ b/servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt @@ -19,10 +19,8 @@ package com.expediagroup.graphql.server.execution import com.expediagroup.graphql.server.types.GraphQLResponse import com.expediagroup.graphql.server.types.GraphQLServerResponse import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -48,21 +46,19 @@ open class GraphQLServer( ): GraphQLServerResponse? = coroutineScope { requestParser.parseRequest(request)?.let { graphQLRequest -> - withContext(Dispatchers.Default) { - val deprecatedContext = contextFactory.generateContext(request) - val contextMap = contextFactory.generateContextMap(request) + val deprecatedContext = contextFactory.generateContext(request) + val contextMap = contextFactory.generateContextMap(request) - val customCoroutineContext = (deprecatedContext?.graphQLCoroutineContext() ?: EmptyCoroutineContext) + - (contextMap[CoroutineContext::class] as? CoroutineContext ?: EmptyCoroutineContext) - val graphQLExecutionScope = CoroutineScope( - coroutineContext + customCoroutineContext + SupervisorJob() - ) - val graphQLContext = contextMap + mapOf( - CoroutineScope::class to graphQLExecutionScope - ) + val customCoroutineContext = (deprecatedContext?.graphQLCoroutineContext() ?: EmptyCoroutineContext) + + (contextMap[CoroutineContext::class] as? CoroutineContext ?: EmptyCoroutineContext) + val graphQLExecutionScope = CoroutineScope( + coroutineContext + customCoroutineContext + SupervisorJob() + ) + val graphQLContext = contextMap + mapOf( + CoroutineScope::class to graphQLExecutionScope + ) - requestHandler.executeRequest(graphQLRequest, deprecatedContext, graphQLContext) - } + requestHandler.executeRequest(graphQLRequest, deprecatedContext, graphQLContext) } } }