Skip to content

Commit a937b8d

Browse files
feat: execute graphQLRequest out of reactor netty threads ( cherry pick #1943) (#1945)
### 📝 Description as soon as request was deserialized, move execution of operation out of the thread that routed the request (reactor netty http epoll thread in case of spring).
1 parent 65aa3f0 commit a937b8d

File tree

1 file changed

+15
-11
lines changed
  • servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution

1 file changed

+15
-11
lines changed

servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package com.expediagroup.graphql.server.execution
1919
import com.expediagroup.graphql.server.types.GraphQLResponse
2020
import com.expediagroup.graphql.server.types.GraphQLServerResponse
2121
import kotlinx.coroutines.CoroutineScope
22+
import kotlinx.coroutines.Dispatchers
2223
import kotlinx.coroutines.SupervisorJob
2324
import kotlinx.coroutines.coroutineScope
25+
import kotlinx.coroutines.withContext
2426
import kotlin.coroutines.CoroutineContext
2527
import kotlin.coroutines.EmptyCoroutineContext
2628

@@ -46,19 +48,21 @@ open class GraphQLServer<Request>(
4648
): GraphQLServerResponse? =
4749
coroutineScope {
4850
requestParser.parseRequest(request)?.let { graphQLRequest ->
49-
val deprecatedContext = contextFactory.generateContext(request)
50-
val contextMap = contextFactory.generateContextMap(request)
51+
withContext(Dispatchers.Default) {
52+
val deprecatedContext = contextFactory.generateContext(request)
53+
val contextMap = contextFactory.generateContextMap(request)
5154

52-
val customCoroutineContext = (deprecatedContext?.graphQLCoroutineContext() ?: EmptyCoroutineContext) +
53-
(contextMap[CoroutineContext::class] as? CoroutineContext ?: EmptyCoroutineContext)
54-
val graphQLExecutionScope = CoroutineScope(
55-
coroutineContext + customCoroutineContext + SupervisorJob()
56-
)
57-
val graphQLContext = contextMap + mapOf(
58-
CoroutineScope::class to graphQLExecutionScope
59-
)
55+
val customCoroutineContext = (deprecatedContext?.graphQLCoroutineContext() ?: EmptyCoroutineContext) +
56+
(contextMap[CoroutineContext::class] as? CoroutineContext ?: EmptyCoroutineContext)
57+
val graphQLExecutionScope = CoroutineScope(
58+
coroutineContext + customCoroutineContext + SupervisorJob()
59+
)
60+
val graphQLContext = contextMap + mapOf(
61+
CoroutineScope::class to graphQLExecutionScope
62+
)
6063

61-
requestHandler.executeRequest(graphQLRequest, deprecatedContext, graphQLContext)
64+
requestHandler.executeRequest(graphQLRequest, deprecatedContext, graphQLContext)
65+
}
6266
}
6367
}
6468
}

0 commit comments

Comments
 (0)