
graphql.nadel.engine.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 Show documentation
Show all versions of nadel Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
package graphql.nadel.engine.transform.hydration
import graphql.nadel.ServiceExecutionResult
import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction
import graphql.nadel.engine.transform.hydration.batch.NadelResolvedObjectBatch
import graphql.nadel.engine.transform.result.NadelResultInstruction
import graphql.nadel.engine.transform.result.json.JsonNode
import graphql.nadel.engine.transform.result.json.JsonNodeExtractor
import graphql.nadel.engine.util.emptyOrSingle
import graphql.nadel.engine.util.toGraphQLError
internal object NadelHydrationUtil {
@JvmName("getInstructionsToAddErrors_2")
fun getInstructionsToAddErrors(
results: List,
): List {
return results
.asSequence()
.map(NadelResolvedObjectBatch::result)
.flatMap(::sequenceOfInstructionsToAddErrors)
.toList()
}
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()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy