Skip to content

Commit 7838268

Browse files
feat(servers): move execution out of reactor netty threads (#1943)
### 📝 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 d8eb4ce commit 7838268

File tree

1 file changed

+14
-10
lines changed
  • servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,8 +21,10 @@ import com.expediagroup.graphql.generator.extensions.plus
2121
import com.expediagroup.graphql.server.types.GraphQLResponse
2222
import com.expediagroup.graphql.server.types.GraphQLServerResponse
2323
import kotlinx.coroutines.CoroutineScope
24+
import kotlinx.coroutines.Dispatchers
2425
import kotlinx.coroutines.SupervisorJob
2526
import kotlinx.coroutines.coroutineScope
27+
import kotlinx.coroutines.withContext
2628
import kotlin.coroutines.CoroutineContext
2729
import kotlin.coroutines.EmptyCoroutineContext
2830

@@ -48,18 +50,20 @@ open class GraphQLServer<Request>(
4850
): GraphQLServerResponse? =
4951
coroutineScope {
5052
requestParser.parseRequest(request)?.let { graphQLRequest ->
51-
val graphQLContext = contextFactory.generateContext(request)
53+
withContext(Dispatchers.Default) {
54+
val graphQLContext = contextFactory.generateContext(request)
5255

53-
val customCoroutineContext = (graphQLContext.get<CoroutineContext>() ?: EmptyCoroutineContext)
54-
val graphQLExecutionScope = CoroutineScope(
55-
coroutineContext + customCoroutineContext + SupervisorJob()
56-
)
56+
val customCoroutineContext = (graphQLContext.get<CoroutineContext>() ?: EmptyCoroutineContext)
57+
val graphQLExecutionScope = CoroutineScope(
58+
coroutineContext + customCoroutineContext + SupervisorJob()
59+
)
5760

58-
val graphQLContextWithCoroutineScope = graphQLContext + mapOf(
59-
CoroutineScope::class to graphQLExecutionScope
60-
)
61+
val graphQLContextWithCoroutineScope = graphQLContext + mapOf(
62+
CoroutineScope::class to graphQLExecutionScope
63+
)
6164

62-
requestHandler.executeRequest(graphQLRequest, graphQLContextWithCoroutineScope)
65+
requestHandler.executeRequest(graphQLRequest, graphQLContextWithCoroutineScope)
66+
}
6367
}
6468
}
6569
}

0 commit comments

Comments
 (0)