From 71444d842a81f66d3fc1fa75f54bf5767608663b Mon Sep 17 00:00:00 2001 From: James Bellenger Date: Sat, 24 May 2025 05:26:01 -0700 Subject: [PATCH 1/2] deterministically serialize SourceLocation --- src/main/java/graphql/GraphqlErrorHelper.java | 5 ++++- .../groovy/graphql/GraphqlErrorHelperTest.groovy | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/graphql/GraphqlErrorHelper.java b/src/main/java/graphql/GraphqlErrorHelper.java index 391b223d92..901c25b5a9 100644 --- a/src/main/java/graphql/GraphqlErrorHelper.java +++ b/src/main/java/graphql/GraphqlErrorHelper.java @@ -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 map = new LinkedHashMap<>(2); + map.put("line", line); + map.put("column", column); + return map; } static List fromSpecification(List> specificationMaps) { diff --git a/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy b/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy index 018c9f1577..5b5ce391c0 100644 --- a/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy +++ b/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy @@ -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 { @@ -120,7 +121,7 @@ class GraphqlErrorHelperTest extends Specification { when: rawError = [message: "m"] - graphQLError = GraphQLError.fromSpecification(rawError) // just so we reference the public method + graphQLError = GraphQLError.fromSpecification(rawError) // vso we reference the public method then: graphQLError.getMessage() == "m" graphQLError.getErrorType() == ErrorType.DataFetchingException // default from error builder @@ -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 + def keys = location.keySet().toList() + keys == ["line", "column"] + } } From baf1125302cac191a10762c49e11f7f15e7a933e Mon Sep 17 00:00:00 2001 From: James Bellenger Date: Sat, 24 May 2025 05:26:47 -0700 Subject: [PATCH 2/2] tidy --- src/test/groovy/graphql/GraphqlErrorHelperTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy b/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy index 5b5ce391c0..0736b1671a 100644 --- a/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy +++ b/src/test/groovy/graphql/GraphqlErrorHelperTest.groovy @@ -121,7 +121,7 @@ class GraphqlErrorHelperTest extends Specification { when: rawError = [message: "m"] - graphQLError = GraphQLError.fromSpecification(rawError) // vso we reference the public method + graphQLError = GraphQLError.fromSpecification(rawError) // just so we reference the public method then: graphQLError.getMessage() == "m" graphQLError.getErrorType() == ErrorType.DataFetchingException // default from error builder