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

graphql.nadel.validation.NadelRenameValidation.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-12-10T04-34-06-f2ee9344
Show newest version
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