graphql.nadel.validation.NadelEnumValidation.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.validation
import graphql.nadel.enginekt.util.strictAssociateBy
import graphql.nadel.validation.NadelSchemaValidationError.MissingUnderlyingEnumValue
import graphql.schema.GraphQLEnumType
import graphql.schema.GraphQLEnumValueDefinition
internal class NadelEnumValidation {
fun validate(
schemaElement: NadelServiceSchemaElement,
): List {
return if (schemaElement.overall is GraphQLEnumType && schemaElement.underlying is GraphQLEnumType) {
validate(
parent = schemaElement,
overallValues = schemaElement.overall.values,
underlyingValues = schemaElement.underlying.values,
)
} else {
emptyList()
}
}
private fun validate(
parent: NadelServiceSchemaElement,
overallValues: List,
underlyingValues: List,
): List {
val underlyingValuesByName = underlyingValues.strictAssociateBy { it.name }
return overallValues.mapNotNull { overallValue ->
val underlyingValue = underlyingValuesByName[overallValue.name]
if (underlyingValue == null) {
MissingUnderlyingEnumValue(parent, overallValue)
} else {
null
}
}
}
}