Skip to content

Commit

Permalink
Refactor source input to be an object
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed Dec 27, 2023
1 parent a93fe91 commit b6f553f
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import graphql.schema.GraphQLTypeUtil
* [NadelBatchHydrationFieldInstruction.batchSize] was exceeded etc.
*/
internal data class NadelHydrationArgumentsBatch(
val sourceIds: List<JsonNode>,
val sourceInputs: List<JsonNode>,
val arguments: Map<NadelHydrationActorInputDef, NormalizedInputValue>,
)

/**
* An [NormalizedInputValue] for one query to a service.
*
* i.e. this object represents one batch of the [sourceIds] values that we send down.
* i.e. this object represents one batch of the [sourceInputs] values that we send down.
*
* An intermediary object to store info while we pass data around functions.
*/
private data class BatchedArgumentValue(
val sourceIds: List<JsonNode>,
val sourceInputs: List<JsonNode>,
val argumentDef: NadelHydrationActorInputDef,
val argumentValue: NormalizedInputValue,
)
Expand All @@ -50,23 +50,23 @@ internal object NadelNewBatchHydrationInputBuilder {
userContext: Any?,
instruction: NadelBatchHydrationFieldInstruction,
hydrationField: ExecutableNormalizedField,
sourceIds: List<JsonNode>,
sourceInputs: List<JsonNode>,
): List<NadelHydrationArgumentsBatch> {
val nonBatchArgs = getNonBatchInputValues(instruction, hydrationField)
val batchArgs = getBatchArgumentValue(instruction, sourceIds, hooks, userContext)
val batchArgs = getBatchArgumentValue(instruction, sourceInputs, hooks, userContext)

return batchArgs
.map { batchedArgument ->
NadelHydrationArgumentsBatch(
arguments = nonBatchArgs + (batchedArgument.argumentDef to batchedArgument.argumentValue),
sourceIds = batchedArgument.sourceIds,
sourceInputs = batchedArgument.sourceInputs,
)
}
}

private fun getBatchArgumentValue(
instruction: NadelBatchHydrationFieldInstruction,
sourceIds: List<JsonNode>,
sourceInputs: List<JsonNode>,
hooks: NadelExecutionHooks,
userContext: Any?,
): List<BatchedArgumentValue> {
Expand All @@ -76,7 +76,7 @@ internal object NadelNewBatchHydrationInputBuilder {
val actorBatchArgDef = instruction.actorFieldDef.getArgument(batchInputDef.name)

val partitionArgumentList = hooks.partitionBatchHydrationArgumentList(
argumentValues = sourceIds.map { it.value },
argumentValues = sourceInputs.map { it.value },
instruction = instruction,
userContext = userContext,
)
Expand All @@ -92,7 +92,7 @@ internal object NadelNewBatchHydrationInputBuilder {
)

BatchedArgumentValue(
sourceIds = chunk
sourceInputs = chunk
.map {
JsonNode(it)
},
Expand Down
Loading

0 comments on commit b6f553f

Please sign in to comment.