Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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);
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)
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"]
}
}