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

Conversation

jbellenger
Copy link
Contributor

@jbellenger jbellenger commented May 24, 2025

In upgrading from 22.3 to 24.0, some of our tests that make assertions on serialized responses started failing.

I think this was probably caused by #3753, which changed the serialized representation from a LinkedHashMap to a Map.of, which has randomized iteration order. This PR brings back the LinkedHashMap serialization format.

I'd appreciate some feedback on this! While the spec doesn't describe how the fields of an error should be ordered, non-deterministic ordering can make it difficult to build reliable tests that interact with GraphQL errors.

@jbellenger jbellenger marked this pull request as ready for review May 24, 2025 12:43
@andimarek
Copy link
Member

Agree ... this was an oversight and we will change it back

@@ -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 ...

@@ -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

@dondonz
Copy link
Member

dondonz commented May 25, 2025

Thanks for the PR!

@dondonz dondonz added this to the 25.x breaking changes milestone May 25, 2025
@dondonz dondonz merged commit 4b1f231 into graphql-java:master May 25, 2025
1 check passed
@dondonz dondonz mentioned this pull request May 26, 2025
@andimarek
Copy link
Member

Hey @jbellenger ... We backported this to 24.1 which is available now.

@jbellenger
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants