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 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.validation
import graphql.nadel.definition.hydration.isHydrated
import graphql.nadel.definition.partition.isPartitioned
import graphql.nadel.definition.renamed.getRenamedOrNull
import graphql.nadel.engine.util.getFieldAt
import graphql.nadel.validation.NadelSchemaValidationError.CannotRenameHydratedField
import graphql.nadel.validation.NadelSchemaValidationError.CannotRenamePartitionedField
import graphql.nadel.validation.NadelSchemaValidationError.MissingRename
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLFieldsContainer
internal class NadelRenameValidation(
private val fieldValidation: NadelFieldValidation,
) {
fun validate(
parent: NadelServiceSchemaElement,
overallField: GraphQLFieldDefinition,
): List {
if (overallField.isHydrated()) {
return listOf(
CannotRenameHydratedField(parent, overallField),
)
}
if (overallField.isPartitioned()) {
return listOf(
CannotRenamePartitionedField(parent, overallField),
)
}
val rename = overallField.getRenamedOrNull()
return if (rename == null) {
listOf()
} else {
val underlyingFieldContainer = parent.underlying as GraphQLFieldsContainer
val underlyingField = underlyingFieldContainer.getFieldAt(rename.from)
if (underlyingField == null) {
listOf(
MissingRename(parent, overallField, rename),
)
} else {
fieldValidation.validate(parent, overallField, underlyingField)
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy