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

graphql.validation.ValidationError Maven / Gradle / Ivy

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


import graphql.ErrorType;
import graphql.GraphQLError;
import graphql.language.SourceLocation;

import java.util.ArrayList;
import java.util.List;

public class ValidationError implements GraphQLError {


    private final ValidationErrorType validationErrorType;
    private final List sourceLocations = new ArrayList();
    private final String description;

    public ValidationError(ValidationErrorType validationErrorType) {
        this(validationErrorType, (SourceLocation) null, null);
    }

    public ValidationError(ValidationErrorType validationErrorType, SourceLocation sourceLocation, String description) {
        this.validationErrorType = validationErrorType;
        if (sourceLocation != null)
            this.sourceLocations.add(sourceLocation);
        this.description = description;
    }

    public ValidationError(ValidationErrorType validationErrorType, List sourceLocations, String description) {
        this.validationErrorType = validationErrorType;
        if (sourceLocations != null)
            this.sourceLocations.addAll(sourceLocations);
        this.description = description;
    }

    public ValidationErrorType getValidationErrorType() {
        return validationErrorType;
    }

    @Override
    public String getMessage() {
        return String.format("Validation error of type %s: %s", validationErrorType, description);
    }

    @Override
    public List getLocations() {
        return sourceLocations;
    }

    @Override
    public ErrorType getErrorType() {
        return ErrorType.ValidationError;
    }


    @Override
    public String toString() {
        return "ValidationError{" +
                "validationErrorType=" + validationErrorType +
                ", sourceLocations=" + sourceLocations +
                ", description='" + description + '\'' +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy