graphql.nadel.validation.NadelRenameValidation.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.getFieldAt
import graphql.nadel.validation.NadelSchemaValidationError.CannotRenameHydratedField
import graphql.nadel.validation.NadelSchemaValidationError.MissingRename
import graphql.nadel.validation.util.NadelSchemaUtil.getRename
import graphql.nadel.validation.util.NadelSchemaUtil.hasHydration
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLFieldsContainer
internal class NadelRenameValidation(
private val fieldValidation: NadelFieldValidation,
) {
fun validate(
parent: NadelServiceSchemaElement,
overallField: GraphQLFieldDefinition,
): List {
if (hasHydration(overallField)) {
return listOf(
CannotRenameHydratedField(parent, overallField),
)
}
val rename = getRename(overallField)
return if (rename == null) {
listOf()
} else {
val underlyingFieldContainer = parent.underlying as GraphQLFieldsContainer
val underlyingField = underlyingFieldContainer.getFieldAt(rename.inputPath)
if (underlyingField == null) {
listOf(
MissingRename(parent, overallField, rename),
)
} else {
fieldValidation.validate(parent, overallField, underlyingField)
}
}
}
}