diff --git a/lib/src/main/java/graphql/nadel/NextgenEngine.kt b/lib/src/main/java/graphql/nadel/NextgenEngine.kt index 1c2914e68..111abbfe4 100644 --- a/lib/src/main/java/graphql/nadel/NextgenEngine.kt +++ b/lib/src/main/java/graphql/nadel/NextgenEngine.kt @@ -58,6 +58,7 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.cancel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.map import kotlinx.coroutines.future.asCompletableFuture import kotlinx.coroutines.future.asDeferred import kotlinx.coroutines.future.await @@ -269,7 +270,10 @@ internal class NextgenEngine( service = service, transformedQuery = transformedQuery, executionContext = executionContext, + executionPlan = executionPlan, executionHydrationDetails = executionContext.hydrationDetails, + artificialFields = queryTransform.artificialFields, + overallToUnderlyingFields = queryTransform.overallToUnderlyingFields, ) } val transformedResult: ServiceExecutionResult = when { @@ -293,7 +297,10 @@ internal class NextgenEngine( service: Service, transformedQuery: ExecutableNormalizedField, executionContext: NadelExecutionContext, + executionPlan: NadelExecutionPlan, executionHydrationDetails: ServiceExecutionHydrationDetails? = null, + artificialFields: List, + overallToUnderlyingFields: Map>, ): ServiceExecutionResult { val timer = executionContext.timer @@ -361,7 +368,21 @@ internal class NextgenEngine( if (serviceExecResult is NadelIncrementalServiceExecutionResult) { executionContext.incrementalResultSupport.defer( - serviceExecResult.incrementalItemPublisher.asFlow() + serviceExecResult.incrementalItemPublisher + .asFlow() + .map { + // Transform + resultTransformer + .transform( + executionContext = executionContext, + executionPlan = executionPlan, + artificialFields = artificialFields, + overallToUnderlyingFields = overallToUnderlyingFields, + service = service, + result = serviceExecResult + ) + it + } ) } diff --git a/lib/src/main/java/graphql/nadel/engine/transform/query/NFUtil.kt b/lib/src/main/java/graphql/nadel/engine/transform/query/NFUtil.kt index 46d165271..829faae78 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/query/NFUtil.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/query/NFUtil.kt @@ -106,7 +106,6 @@ object NFUtil { return ExecutableNormalizedField.newNormalizedField() .objectTypeNames(listOf(parentType.name)) .fieldName(fieldName) - //.deferredExecutions() // <-- add defer execution .deferredExecutions(deferredExecutions) .also { builder -> if (pathToFieldIndex == queryPathToField.segments.lastIndex) { diff --git a/lib/src/main/java/graphql/nadel/engine/transform/result/NadelResultTransformer.kt b/lib/src/main/java/graphql/nadel/engine/transform/result/NadelResultTransformer.kt index e13f25e91..6cf1bf8b6 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/result/NadelResultTransformer.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/result/NadelResultTransformer.kt @@ -1,10 +1,13 @@ package graphql.nadel.engine.transform.result +import graphql.incremental.DelayedIncrementalPartialResultImpl +import graphql.nadel.NadelIncrementalServiceExecutionResult import graphql.nadel.Service import graphql.nadel.ServiceExecutionResult import graphql.nadel.engine.NadelExecutionContext import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprint import graphql.nadel.engine.plan.NadelExecutionPlan +import graphql.nadel.engine.transform.query.NadelQueryPath import graphql.nadel.engine.transform.result.json.JsonNodes import graphql.nadel.engine.util.JsonMap import graphql.nadel.engine.util.MutableJsonMap @@ -14,6 +17,8 @@ import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.reactive.asFlow internal class NadelResultTransformer(private val executionBlueprint: NadelOverallExecutionBlueprint) { suspend fun transform( @@ -24,11 +29,47 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera service: Service, result: ServiceExecutionResult, ): ServiceExecutionResult { + //NadelIncrementalServiceExecutionResult -> IncrementalItemPublisher.map (apply transforms to every itme in publisher) + //result + if (result is NadelIncrementalServiceExecutionResult) { + result.incrementalItemPublisher.asFlow() + .map { + val incremental = it.incremental + ?.map { + + } + DelayedIncrementalPartialResultImpl.newIncrementalExecutionResult() + + .extensions(it.extensions) + .build() + } + } + // maybe here or in NextGenEngine val nodes = JsonNodes(result.data) - - val deferredInstructions = ArrayList>>() - + nodes.getNodesAt(NadelQueryPath(listOf("issue", "user"))) + + val asyncInstructions = ArrayList>>() + + // issue { + // ... @defer { + // user { + // name # @renamed(from: "asdfaiowjefwef") + // } + // } + // key # @renamed(from: "asdf") + // } + // "incremtanl": [ + // { + // "data": { + // "user": { + // name: "Steven" + // } + // } + // "path": [issue] + // } + // ] coroutineScope { + // transform step of field [issue -> user -> name] for ((field, steps) in executionPlan.transformationSteps) { // This can be null if we did not end up sending the field e.g. for hydration val underlyingFields = overallToUnderlyingFields[field] @@ -37,7 +78,7 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera } for (step in steps) { - deferredInstructions.add( + asyncInstructions.add( async { step.transform.getResultInstructions( executionContext, @@ -54,14 +95,14 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera } } - deferredInstructions.add( + asyncInstructions.add( async { getRemoveArtificialFieldInstructions(artificialFields, nodes) }, ) } - val instructions = deferredInstructions + val instructions = asyncInstructions .awaitAll() .flatten()