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

graphql.validation.rules.KnownFragmentNames Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.validation.rules;


import graphql.Internal;
import graphql.language.FragmentDefinition;
import graphql.language.FragmentSpread;
import graphql.validation.AbstractRule;
import graphql.validation.ValidationContext;
import graphql.validation.ValidationErrorCollector;
import graphql.validation.ValidationErrorType;

@Internal
public class KnownFragmentNames extends AbstractRule {

    public KnownFragmentNames(ValidationContext validationContext, ValidationErrorCollector validationErrorCollector) {
        super(validationContext, validationErrorCollector);
    }

    @Override
    public void checkFragmentSpread(FragmentSpread fragmentSpread) {
        FragmentDefinition fragmentDefinition = getValidationContext().getFragment(fragmentSpread.getName());
        if (fragmentDefinition == null) {
            String message = String.format("Undefined fragment %s", fragmentSpread.getName());
            addError(ValidationErrorType.UndefinedFragment, fragmentSpread.getSourceLocation(), message);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy