All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.nadel.validation.NadelNamespaceValidation.kt Maven / Gradle / Ivy

Go to download

Nadel is a Java library that combines multiple GrahpQL services together into one API.

There is a newer version: 2024-11-20T03-31-21-302962b7
Show newest version
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
                    }
            }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy