graphql.nadel.validation.NadelNamespaceValidation.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.engine.util.operationTypes
import graphql.nadel.engine.util.unwrapAll
import graphql.nadel.util.NamespacedUtil.isNamespacedField
import graphql.nadel.validation.NadelSchemaValidationError.NamespacedTypeMustBeObject
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
class NadelNamespaceValidation(
private val overallSchema: GraphQLSchema,
) {
fun validate(
schemaElement: NadelServiceSchemaElement,
): List {
if (!isNamespacedOperationType(typeName = schemaElement.overall.name)) {
return emptyList()
}
if (schemaElement.overall !is GraphQLObjectType) {
return listOf(NamespacedTypeMustBeObject(schemaElement))
}
return emptyList()
}
fun isNamespacedOperationType(typeName: String): Boolean {
return overallSchema.operationTypes
.any { operationType ->
operationType.fields
.any { field ->
isNamespacedField(field) && field.type.unwrapAll().name == typeName
}
}
}
}