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

graphql.validation.ValidationError Maven / Gradle / Ivy

The 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 + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        return Helper.equals(this, o);
    }

    @Override
    public int hashCode() {
        return Helper.hashCode(this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy