Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor source input to be an object #506

Merged
merged 1 commit into from
Jan 16, 2024
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 @@ -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
Loading