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.

The newest version!
package graphql.nadel.validation

import graphql.nadel.enginekt.util.getFieldAt
import graphql.nadel.validation.NadelSchemaValidationError.CannotRenameHydratedField
import graphql.nadel.validation.NadelSchemaValidationError.MissingRename
import graphql.nadel.validation.util.NadelSchemaUtil.getRename
import graphql.nadel.validation.util.NadelSchemaUtil.hasHydration
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLFieldsContainer

internal class NadelRenameValidation(
    private val fieldValidation: NadelFieldValidation,
) {
    fun validate(
        parent: NadelServiceSchemaElement,
        overallField: GraphQLFieldDefinition,
    ): List {
        if (hasHydration(overallField)) {
            return listOf(
                CannotRenameHydratedField(parent, overallField),
            )
        }

        val rename = getRename(overallField)

        return if (rename == null) {
            listOf()
        } else {
            val underlyingFieldContainer = parent.underlying as GraphQLFieldsContainer
            val underlyingField = underlyingFieldContainer.getFieldAt(rename.inputPath)
            if (underlyingField == null) {
                listOf(
                    MissingRename(parent, overallField, rename),
                )
            } else {
                fieldValidation.validate(parent, overallField, underlyingField)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy