-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement equals/hashCode for GraphqlErrorImpl #3720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement equals/hashCode for GraphqlErrorImpl #3720
Conversation
We have a great many tests that verify that the errors emitted from a `DataFetcher` fit a certain shape. However, verifying equality of these errors is fiddly and error-prone, as we must directly check each individual attribute on every error - this is painful especially when we are trying to perform assertions on a `List` of `GraphQLError`s. To this end, we add `#equals` / `#hashCode` methods on `GraphqlErrorImpl`. However, it is important to note that `equals` will return `true` if all the attributes match, even if the implementing class is _not_ a `GraphqlErrorImpl`. This is done so that different implementations may be swapped in and out with causing test failures.
GraphQLError that = (GraphQLError) o; | ||
return Objects.equals(getMessage(), that.getMessage()) | ||
&& Objects.equals(getLocations(), that.getLocations()) | ||
&& Objects.equals(getErrorType(), that.getErrorType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graphql.ErrorClassification
is an interface so this is a place where technically a bad graphql.ErrorClassification
would break you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now added this in the Javadoc - is there another way you would like this to be handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No just articulating a challenge
errors == [error2, error3] as Set | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have some more tests cases with the other attrs such as source location, path say please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I've structured this in such a way that should make it easy to add more tests if the existing coverage is not enough.
This now tests the other attributes, and also checks inequality explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution
We have a great many tests that verify that the errors emitted from a
DataFetcher
fit a certain shape.However, verifying equality of these errors is fiddly and error-prone, as we must directly check each individual attribute on every error - this is painful especially when we are trying to perform assertions on a
List
ofGraphQLError
s.To this end, we add
#equals
/#hashCode
methods onGraphqlErrorImpl
. However, it is important to note thatequals
will returntrue
if all the attributes match, even if the implementing class is not aGraphqlErrorImpl
. This is done so that different implementations may be swapped in and out with causing test failures.