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

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

Go to download

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
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy