Skip to content

Commit

Permalink
Add feature flag for new batch hydrator (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf authored Nov 8, 2023
1 parent 8bc3a66 commit 4c563ba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/src/main/java/graphql/nadel/NadelExecutionHints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package graphql.nadel

import graphql.nadel.hints.AllDocumentVariablesHint
import graphql.nadel.hints.LegacyOperationNamesHint
import graphql.nadel.hints.NewBatchHydrationGroupingHint
import graphql.nadel.hints.NewResultMergerAndNamespacedTypename

data class NadelExecutionHints constructor(
data class NadelExecutionHints(
val legacyOperationNames: LegacyOperationNamesHint,
val allDocumentVariablesHint: AllDocumentVariablesHint,
val newResultMergerAndNamespacedTypename: NewResultMergerAndNamespacedTypename,
val newBatchHydrationGrouping: NewBatchHydrationGroupingHint,
) {
/**
* Returns a builder with the same field values as this object.
Expand All @@ -20,9 +22,10 @@ data class NadelExecutionHints constructor(
}

class Builder {
private var legacyOperationNames: LegacyOperationNamesHint = LegacyOperationNamesHint { false }
private var allDocumentVariablesHint: AllDocumentVariablesHint = AllDocumentVariablesHint { false }
private var newResultMergerAndNamespacedTypename: NewResultMergerAndNamespacedTypename = NewResultMergerAndNamespacedTypename { false }
private var legacyOperationNames = LegacyOperationNamesHint { false }
private var allDocumentVariablesHint = AllDocumentVariablesHint { false }
private var newResultMergerAndNamespacedTypename = NewResultMergerAndNamespacedTypename { false }
private var newBatchHydrationGrouping = NewBatchHydrationGroupingHint { false }

constructor()

Expand All @@ -47,11 +50,17 @@ data class NadelExecutionHints constructor(
return this
}

fun newBatchHydrationGrouping(flag: NewBatchHydrationGroupingHint): Builder {
newBatchHydrationGrouping = flag
return this
}

fun build(): NadelExecutionHints {
return NadelExecutionHints(
legacyOperationNames,
allDocumentVariablesHint,
newResultMergerAndNamespacedTypename,
newBatchHydrationGrouping,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class NadelBatchHydrationTransform(
engine: NextgenEngine,
) : NadelTransform<State> {
private val hydrator = NadelBatchHydrator(engine)
private val newHydrator = NadelNewBatchHydrator(engine)

data class State(
val executionBlueprint: NadelOverallExecutionBlueprint,
Expand Down Expand Up @@ -115,7 +116,11 @@ internal class NadelBatchHydrationTransform(
flatten = true,
)

return hydrator.hydrate(state, executionBlueprint, parentNodes)
if (executionContext.hints.newBatchHydrationGrouping()) {
return newHydrator.hydrate(state, executionBlueprint, parentNodes)
} else {
return hydrator.hydrate(state, executionBlueprint, parentNodes)
}
}

private fun makeTypeNameField(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package graphql.nadel.engine.transform.hydration.batch

import graphql.nadel.NextgenEngine
import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprint
import graphql.nadel.engine.transform.hydration.batch.NadelBatchHydrationTransform.State
import graphql.nadel.engine.transform.result.NadelResultInstruction
import graphql.nadel.engine.transform.result.json.JsonNode

internal class NadelNewBatchHydrator(
private val engine: NextgenEngine,
) {
fun hydrate(
state: State,
executionBlueprint: NadelOverallExecutionBlueprint,
parentNodes: List<JsonNode>,
): List<NadelResultInstruction> {
throw UnsupportedOperationException()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package graphql.nadel.hints

fun interface NewBatchHydrationGroupingHint {
/**
* Uses new grouping algorithm for batched hydrations.
*/
operator fun invoke(): Boolean
}

0 comments on commit 4c563ba

Please sign in to comment.