Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/main/java/graphql/schema/validation/SchemaValidationError.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@

import graphql.Internal;

import java.util.Objects;
import java.util.StringJoiner;

import static graphql.Assert.assertNotNull;

@Internal
public class SchemaValidationError {

private final SchemaValidationErrorType errorType;
private final SchemaValidationErrorClassification errorClassification;
private final String description;

public SchemaValidationError(SchemaValidationErrorType errorType, String description) {
assertNotNull(errorType, () -> "error type can not be null");
public SchemaValidationError(SchemaValidationErrorType errorClassification, String description) {
assertNotNull(errorClassification, () -> "error classification can not be null");
assertNotNull(description, () -> "error description can not be null");
this.errorType = errorType;
this.errorClassification = errorClassification;
this.description = description;
}

public SchemaValidationErrorType getErrorType() {
return errorType;
public SchemaValidationErrorClassification getClassification() {
return errorClassification;
}

public String getDescription() {
Expand All @@ -31,15 +30,15 @@ public String getDescription() {
@Override
public String toString() {
return new StringJoiner(", ", SchemaValidationError.class.getSimpleName() + "[", "]")
.add("errorType=" + errorType)
.add("errorClassification=" + errorClassification)
.add("description='" + description + "'")
.toString();
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + errorType.hashCode();
result = 31 * result + errorClassification.hashCode();
result = 31 * result + description.hashCode();
return result;
}
Expand All @@ -53,6 +52,6 @@ public boolean equals(Object other) {
return false;
}
SchemaValidationError that = (SchemaValidationError) other;
return this.errorType.equals(that.errorType) && this.description.equals(that.description);
return this.errorClassification.equals(that.errorClassification) && this.description.equals(that.description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package graphql.schema.validation;


import graphql.PublicApi;


/**
* Error in graphql schema validation can have a classification,
* and all the error classifications implement this interface.
*/
@PublicApi
public interface SchemaValidationErrorClassification {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Set<SchemaValidationError> getErrors() {

public boolean containsValidationError(SchemaValidationErrorType validationErrorType) {
for (SchemaValidationError validationError : errors) {
if (validationError.getErrorType() == validationErrorType) return true;
if (validationError.getClassification() == validationErrorType) return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import graphql.Internal;

@Internal
public enum SchemaValidationErrorType {
public enum SchemaValidationErrorType implements SchemaValidationErrorClassification{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah enums are a mistake in an API - albeit this is not actually API yet but rather @internal

Either way enums lock you into a close type system and that is bad for errors since we can always invent new errors and error types


UnbrokenInputCycle,
ObjectDoesNotImplementItsInterfaces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import graphql.schema.GraphQLTypeReference
import graphql.schema.TypeResolverProxy
import spock.lang.Specification

import static graphql.Scalars.GraphQLBoolean
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
import static graphql.schema.GraphQLObjectType.newObject
import static graphql.schema.GraphQLUnionType.newUnionType

class TypeAndFieldRuleTest extends Specification {
Expand Down Expand Up @@ -127,7 +124,7 @@ class TypeAndFieldRuleTest extends Specification {
then:
InvalidSchemaException e = thrown(InvalidSchemaException)
!e.getErrors().isEmpty()
e.getErrors()[0].errorType == SchemaValidationErrorType.InvalidUnionMemberTypeError
e.getErrors()[0].classification == SchemaValidationErrorType.InvalidUnionMemberTypeError
}

def "union member types must be unique"() {
Expand Down Expand Up @@ -160,6 +157,6 @@ class TypeAndFieldRuleTest extends Specification {
then:
InvalidSchemaException e = thrown(InvalidSchemaException)
!e.getErrors().isEmpty()
e.getErrors()[0].errorType == SchemaValidationErrorType.RepetitiveElementError
e.getErrors()[0].classification == SchemaValidationErrorType.RepetitiveElementError
}
}