Skip to content

Commit

Permalink
stashed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarker2 committed Aug 5, 2024
1 parent 7305c42 commit 4b69623
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
23 changes: 22 additions & 1 deletion lib/src/main/java/graphql/nadel/NextgenEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -293,7 +297,10 @@ internal class NextgenEngine(
service: Service,
transformedQuery: ExecutableNormalizedField,
executionContext: NadelExecutionContext,
executionPlan: NadelExecutionPlan,
executionHydrationDetails: ServiceExecutionHydrationDetails? = null,
artificialFields: List<ExecutableNormalizedField>,
overallToUnderlyingFields: Map<ExecutableNormalizedField, List<ExecutableNormalizedField>>,
): ServiceExecutionResult {
val timer = executionContext.timer

Expand Down Expand Up @@ -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
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -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<Deferred<List<NadelResultInstruction>>>()

nodes.getNodesAt(NadelQueryPath(listOf("issue", "user")))

val asyncInstructions = ArrayList<Deferred<List<NadelResultInstruction>>>()

// 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]
Expand All @@ -37,7 +78,7 @@ internal class NadelResultTransformer(private val executionBlueprint: NadelOvera
}

for (step in steps) {
deferredInstructions.add(
asyncInstructions.add(
async {
step.transform.getResultInstructions(
executionContext,
Expand All @@ -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()

Expand Down

0 comments on commit 4b69623

Please sign in to comment.