graphql.validation.ValidationError Maven / Gradle / Ivy
package graphql.validation;
import graphql.DeprecatedAt;
import graphql.ErrorType;
import graphql.GraphQLError;
import graphql.GraphqlErrorHelper;
import graphql.PublicApi;
import graphql.language.SourceLocation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@PublicApi
public class ValidationError implements GraphQLError {
private final String message;
private final List locations = new ArrayList<>();
private final String description;
private final ValidationErrorClassification validationErrorType;
private final List queryPath;
private final Map extensions;
@Deprecated
@DeprecatedAt("2022-07-10")
public ValidationError(ValidationErrorClassification validationErrorType) {
this(newValidationError()
.validationErrorType(validationErrorType));
}
@Deprecated
@DeprecatedAt("2022-07-10")
public ValidationError(ValidationErrorClassification validationErrorType, SourceLocation sourceLocation, String description) {
this(newValidationError()
.validationErrorType(validationErrorType)
.sourceLocation(sourceLocation)
.description(description));
}
@Deprecated
@DeprecatedAt("2022-07-10")
public ValidationError(ValidationErrorType validationErrorType, SourceLocation sourceLocation, String description, List queryPath) {
this(newValidationError()
.validationErrorType(validationErrorType)
.sourceLocation(sourceLocation)
.description(description)
.queryPath(queryPath));
}
@Deprecated
@DeprecatedAt("2022-07-10")
public ValidationError(ValidationErrorType validationErrorType, List sourceLocations, String description) {
this(newValidationError()
.validationErrorType(validationErrorType)
.sourceLocations(sourceLocations)
.description(description));
}
@Deprecated
@DeprecatedAt("2022-07-10")
public ValidationError(ValidationErrorType validationErrorType, List sourceLocations, String description, List queryPath) {
this(newValidationError()
.validationErrorType(validationErrorType)
.sourceLocations(sourceLocations)
.description(description)
.queryPath(queryPath));
}
private ValidationError(Builder builder) {
this.validationErrorType = builder.validationErrorType;
if (builder.sourceLocations != null) {
this.locations.addAll(builder.sourceLocations);
}
this.description = builder.description;
this.message = builder.description;
this.queryPath = builder.queryPath;
this.extensions = builder.extensions;
}
public ValidationErrorClassification getValidationErrorType() {
return validationErrorType;
}
@Override
public String getMessage() {
return message;
}
public String getDescription() {
return description;
}
@Override
public List getLocations() {
return locations;
}
@Override
public ErrorType getErrorType() {
return ErrorType.ValidationError;
}
public List getQueryPath() {
return queryPath;
}
@Override
public Map getExtensions() {
return extensions;
}
@Override
public String toString() {
return "ValidationError{" +
"validationErrorType=" + validationErrorType +
", queryPath=" + queryPath +
", message=" + message +
", locations=" + locations +
", description='" + description + '\'' +
'}';
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(Object o) {
return GraphqlErrorHelper.equals(this, o);
}
@Override
public int hashCode() {
return GraphqlErrorHelper.hashCode(this);
}
public static Builder newValidationError() {
return new Builder();
}
public static class Builder {
private List sourceLocations;
private Map extensions;
private String description;
private ValidationErrorClassification validationErrorType;
private List queryPath;
public Builder validationErrorType(ValidationErrorClassification validationErrorType) {
this.validationErrorType = validationErrorType;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder queryPath(List queryPath) {
this.queryPath = queryPath;
return this;
}
public Builder sourceLocation(SourceLocation sourceLocation) {
this.sourceLocations = sourceLocation == null ? null : Collections.singletonList(sourceLocation);
return this;
}
public Builder sourceLocations(List sourceLocations) {
this.sourceLocations = sourceLocations;
return this;
}
public Builder extensions(Map extensions) {
this.extensions = extensions;
return this;
}
public ValidationError build() {
return new ValidationError(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy