-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,4 +152,66 @@ class GraphqlErrorBuilderTest extends Specification { | |
| error.path == null | ||
|
|
||
| } | ||
| } | ||
|
|
||
| def "implements equals/hashCode correctly for matching errors"() { | ||
| when: | ||
| def firstError = toGraphQLError(first) | ||
| def secondError = toGraphQLError(second) | ||
|
|
||
| then: | ||
| firstError == secondError | ||
| firstError.hashCode() == secondError.hashCode() | ||
|
|
||
| where: | ||
| first | second | ||
| [message: "msg"] | [message: "msg"] | ||
| [message: "msg", locations: [new SourceLocation(1, 2)]] | [message: "msg", locations: [new SourceLocation(1, 2)]] | ||
| [message: "msg", errorType: ErrorType.InvalidSyntax] | [message: "msg", errorType: ErrorType.InvalidSyntax] | ||
| [message: "msg", path: ["items", 1, "item"]] | [message: "msg", path: ["items", 1, "item"]] | ||
| [message: "msg", extensions: [aBoolean: true, aString: "foo"]] | [message: "msg", extensions: [aBoolean: true, aString: "foo"]] | ||
| } | ||
|
|
||
| def "implements equals/hashCode correctly for different errors"() { | ||
| when: | ||
| def firstError = toGraphQLError(first) | ||
| def secondError = toGraphQLError(second) | ||
|
|
||
| then: | ||
| firstError != secondError | ||
| firstError.hashCode() != secondError.hashCode() | ||
|
|
||
| where: | ||
| first | second | ||
| [message: "msg"] | [message: "different msg"] | ||
| [message: "msg", locations: [new SourceLocation(1, 2)]] | [message: "msg", locations: [new SourceLocation(3, 4)]] | ||
| [message: "msg", errorType: ErrorType.InvalidSyntax] | [message: "msg", errorType: ErrorType.DataFetchingException] | ||
| [message: "msg", path: ["items", "1", "item"]] | [message: "msg", path: ["items"]] | ||
| [message: "msg", extensions: [aBoolean: false]] | [message: "msg", extensions: [aString: "foo"]] | ||
| } | ||
|
|
||
| private static GraphQLError toGraphQLError(Map<String, Object> errorFields) { | ||
| def errorBuilder = GraphQLError.newError(); | ||
| errorFields.forEach { key, value -> | ||
| if (value != null) { | ||
| switch (key) { | ||
| case "message": | ||
| errorBuilder.message(value as String); | ||
| break; | ||
| case "locations": | ||
| errorBuilder.locations(value as List<SourceLocation>); | ||
| break; | ||
| case "errorType": | ||
| errorBuilder.errorType(value as ErrorClassification); | ||
| break; | ||
| case "path": | ||
| errorBuilder.path(value as List<Object>); | ||
| break; | ||
| case "extensions": | ||
| errorBuilder.extensions(value as Map<String, Object>); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return errorBuilder.build(); | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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.ErrorClassificationis an interface so this is a place where technically a badgraphql.ErrorClassificationwould break youThere 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