Skip to content

deterministic SourceLocation serialization #3987

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

Merged
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
5 changes: 4 additions & 1 deletion src/main/java/graphql/GraphqlErrorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public static Object location(SourceLocation location) {
if (line < 1 || column < 1) {
return null;
}
return Map.of("line", line, "column", column);
LinkedHashMap<String, Object> map = new LinkedHashMap<>(2);
Copy link
Member

Choose a reason for hiding this comment

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

Don't we have a Util method for that? Maybe not, but we should have that emulates the Map.of ...

map.put("line", line);
map.put("column", column);
return map;
}

static List<GraphQLError> fromSpecification(List<Map<String, Object>> specificationMaps) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/groovy/graphql/GraphqlErrorHelperTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graphql
import graphql.language.SourceLocation
import graphql.validation.ValidationError
import graphql.validation.ValidationErrorType
import spock.lang.RepeatUntilFailure
import spock.lang.Specification

class GraphqlErrorHelperTest extends Specification {
Expand Down Expand Up @@ -154,4 +155,15 @@ class GraphqlErrorHelperTest extends Specification {
assert gErr.getExtensions() == null
}
}

@RepeatUntilFailure(maxAttempts = 1_000)
Copy link
Member

Choose a reason for hiding this comment

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

Oh ... never knew that annotation ... learned that something new here

def "can deterministically serialize SourceLocation"() {
when:
def specMap = GraphqlErrorHelper.toSpecification(new TestError())

then:
def location = specMap["locations"][0] as Map<String, Object>
def keys = location.keySet().toList()
keys == ["line", "column"]
}
}