Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal typealias AnyNadelExecutionPlanStep = NadelExecutionPlan.Step<Any>
data class NadelExecutionPlan(
// this is a map for overall Fields
val transformationSteps: Map<ExecutableNormalizedField, List<AnyNadelExecutionPlanStep>>,
val transformContexts: Map<NadelTransform<Any>, NadelTransformServiceExecutionContext?>,
) {
data class Step<T : Any>(
val service: Service,
Expand All @@ -19,21 +20,5 @@ data class NadelExecutionPlan(
val queryTransformTimingStep: NadelInstrumentationTimingParameters.Step,
val resultTransformTimingStep: NadelInstrumentationTimingParameters.Step,
val state: T,
val transformServiceExecutionContext: NadelTransformServiceExecutionContext?,
)

/**
* Creates and returns a new [NadelExecutionPlan] that is a merging of `this` plan
* and the [other] plan.
*/
fun merge(other: NadelExecutionPlan): NadelExecutionPlan {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever use it and I don't think we can do it now that we store a context by transform

val newSteps = transformationSteps.toMutableMap()
other.transformationSteps.forEach { (field, steps) ->
newSteps.compute(field) { _, oldSteps ->
oldSteps?.let { it + steps } ?: steps
}
}

return copy(transformationSteps = newSteps)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ internal class NadelExecutionPlanFactory(
queryTransformTimingStep = transformWithTimingInfo.queryTransformTimingStep,
resultTransformTimingStep = transformWithTimingInfo.resultTransformTimingStep,
state = state,
executionTransformContext
)
}
}
Expand All @@ -127,7 +126,10 @@ internal class NadelExecutionPlanFactory(
}
}

return NadelExecutionPlan(executionSteps)
return NadelExecutionPlan(
executionSteps,
transformContexts
)
}

private inline fun traverseQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface NadelTransformJavaCompat<State : Any> {
service: Service,
rootField: ExecutableNormalizedField,
hydrationDetails: ServiceExecutionHydrationDetails?,
): NadelTransformServiceExecutionContext? {
return null
): CompletableFuture<NadelTransformServiceExecutionContext?> {
return CompletableFuture.completedFuture(null)
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ interface NadelTransformJavaCompat<State : Any> {
service,
rootField,
hydrationDetails
)
).asDeferred().await()
}

override suspend fun isApplicable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class NadelQueryTransformer private constructor(
val artificialFields = mutableListOf<ExecutableNormalizedField>()

for (transformStep in transformationSteps) {
val transformServiceExecutionContext = executionPlan.transformContexts[transformStep.transform]
val transformResultForStep = timer.time(transformStep.queryTransformTimingStep) {
transformStep.transform.transformField(
executionContext,
Expand All @@ -175,7 +176,7 @@ class NadelQueryTransformer private constructor(
service,
newField,
transformStep.state,
transformStep.transformServiceExecutionContext
transformServiceExecutionContext
)
}
artificialFields.addAll(transformResultForStep.artificialFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import graphql.nadel.engine.NadelExecutionContext
import graphql.nadel.engine.NadelServiceExecutionContext
import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprint
import graphql.nadel.engine.plan.NadelExecutionPlan
import graphql.nadel.engine.transform.NadelTransform
import graphql.nadel.engine.transform.NadelTransformServiceExecutionContext
import graphql.nadel.engine.transform.query.NadelQueryPath
import graphql.nadel.engine.transform.result.json.JsonNodes
import graphql.nadel.engine.util.JsonMap
Expand All @@ -20,6 +18,7 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

internal class NadelResultTransformer(private val executionBlueprint: NadelOverallExecutionBlueprint) {
suspend fun transform(
Expand Down Expand Up @@ -85,15 +84,15 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera
nodes: JsonNodes,
): List<NadelResultInstruction> {
val asyncInstructions = ArrayList<Deferred<List<NadelResultInstruction>>>()
val contextByTransform = mutableMapOf<NadelTransform<Any>, NadelTransformServiceExecutionContext?>()
val contextByTransform = executionPlan.transformContexts
coroutineScope {
executionContext.timer.batch { timer ->
for ((field, steps) in executionPlan.transformationSteps) {
val underlyingFields = overallToUnderlyingFields[field]
if (underlyingFields.isNullOrEmpty()) continue

for (step in steps) {
contextByTransform.putIfAbsent(step.transform, step.transformServiceExecutionContext)
val transformServiceExecutionContext = contextByTransform[step.transform]
asyncInstructions.add(
async {
timer.time(step.resultTransformTimingStep) {
Expand All @@ -107,7 +106,7 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera
result,
step.state,
nodes,
step.transformServiceExecutionContext
transformServiceExecutionContext
)
}
}
Expand All @@ -125,8 +124,8 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera
val instructions = asyncInstructions.awaitAll().flatten()

coroutineScope {
val finalizeJobs = contextByTransform.map { (transform, transformServiceExecutionContext) ->
async {
contextByTransform.forEach { (transform, transformServiceExecutionContext) ->
launch {
transform.onComplete(
executionContext,
serviceExecutionContext,
Expand All @@ -138,9 +137,7 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera
)
}
}
finalizeJobs.awaitAll()
}

return instructions
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class NadelTransformJavaCompatTest : DescribeSpec({
service: Service,
rootField: ExecutableNormalizedField,
hydrationDetails: ServiceExecutionHydrationDetails?,
): NadelTransformServiceExecutionContext? {
return Prop("something")
): CompletableFuture<NadelTransformServiceExecutionContext?> {
return CompletableFuture.completedFuture(Prop("something"))
}
})

Expand Down