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
2121import com.expediagroup.graphql.server.types.GraphQLResponse
2222import com.expediagroup.graphql.server.types.GraphQLServerResponse
2323import kotlinx.coroutines.CoroutineScope
24+ import kotlinx.coroutines.Dispatchers
2425import kotlinx.coroutines.SupervisorJob
2526import kotlinx.coroutines.coroutineScope
27+ import kotlinx.coroutines.withContext
2628import kotlin.coroutines.CoroutineContext
2729import 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