graphql.nadel.enginekt.transform.hydration.NadelHydrationUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadel-engine-nextgen Show documentation
Show all versions of nadel-engine-nextgen Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
The newest version!
package graphql.nadel.enginekt.transform.hydration
import graphql.nadel.ServiceExecutionResult
import graphql.nadel.enginekt.blueprint.NadelGenericHydrationInstruction
import graphql.nadel.enginekt.transform.result.NadelResultInstruction
import graphql.nadel.enginekt.transform.result.json.JsonNode
import graphql.nadel.enginekt.transform.result.json.JsonNodeExtractor
import graphql.nadel.enginekt.util.emptyOrSingle
import graphql.nadel.enginekt.util.toGraphQLError
internal object NadelHydrationUtil {
fun getInstructionsToAddErrors(
results: List,
): List {
return results
.asSequence()
.flatMap(::sequenceOfInstructionsToAddErrors)
.toList()
}
fun getInstructionsToAddErrors(
result: ServiceExecutionResult,
): List {
return sequenceOfInstructionsToAddErrors(result).toList()
}
/**
* Do not expose sequences as those
*/
private fun sequenceOfInstructionsToAddErrors(
result: ServiceExecutionResult,
): Sequence {
return result.errors
.asSequence()
.map(::toGraphQLError)
.map(NadelResultInstruction::AddError)
}
fun getHydrationActorNodes(
instruction: NadelGenericHydrationInstruction,
batches: List,
): List {
return batches
.asSequence()
.mapNotNull { batch ->
getHydrationActorNode(instruction, batch)
}
.toList()
}
fun getHydrationActorNode(
instruction: NadelGenericHydrationInstruction,
batch: ServiceExecutionResult,
): JsonNode? {
return JsonNodeExtractor.getNodesAt(
data = batch.data ?: return null,
queryPath = instruction.queryPathToActorField,
).emptyOrSingle()
}
}