Skip to content

Commit 4b1f231

Browse files
authored
Merge pull request #3987 from jbellenger/jbellenger-error-location-ordering
deterministic SourceLocation serialization
2 parents eccc34a + baf1125 commit 4b1f231

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/graphql/GraphqlErrorHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public static Object location(SourceLocation location) {
7373
if (line < 1 || column < 1) {
7474
return null;
7575
}
76-
return Map.of("line", line, "column", column);
76+
LinkedHashMap<String, Object> map = new LinkedHashMap<>(2);
77+
map.put("line", line);
78+
map.put("column", column);
79+
return map;
7780
}
7881

7982
static List<GraphQLError> fromSpecification(List<Map<String, Object>> specificationMaps) {

src/test/groovy/graphql/GraphqlErrorHelperTest.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package graphql
33
import graphql.language.SourceLocation
44
import graphql.validation.ValidationError
55
import graphql.validation.ValidationErrorType
6+
import spock.lang.RepeatUntilFailure
67
import spock.lang.Specification
78

89
class GraphqlErrorHelperTest extends Specification {
@@ -154,4 +155,15 @@ class GraphqlErrorHelperTest extends Specification {
154155
assert gErr.getExtensions() == null
155156
}
156157
}
158+
159+
@RepeatUntilFailure(maxAttempts = 1_000)
160+
def "can deterministically serialize SourceLocation"() {
161+
when:
162+
def specMap = GraphqlErrorHelper.toSpecification(new TestError())
163+
164+
then:
165+
def location = specMap["locations"][0] as Map<String, Object>
166+
def keys = location.keySet().toList()
167+
keys == ["line", "column"]
168+
}
157169
}

0 commit comments

Comments
 (0)