Skip to content

Conversation

@federicorispo
Copy link
Contributor

@federicorispo federicorispo commented Nov 21, 2022

  • Updated toString method in ValidationError class to print the extensions field. If the field is null then an empty array will be printed ...extensions=[]
  • Removed the message field because it was always initialized with the description but the getMessage() method is still there and returns the content of the description
  • Initialized the extensions and queryPath fields during their declaration to align with the sourceLocations field
  • Added a couple of UTs to test the ValidationError#toString method

It resolves #3005

federicorispo and others added 4 commits November 20, 2022 00:19
 - Updated toString method in ValidationError class to print the extensions field. If the field is null then an empty
   array will be printed `...extensions=[]`
 - Added a couple of UTs to test the ValidationError#toString method
….com:federicorispo/graphql-java into chore/fix-tostring-method-in-validationerror
@federicorispo federicorispo changed the title chore: update ValidationError#toString to print the extentions field Update ValidationError#toString to print the extentions field Nov 21, 2022
}

if (builder.extensions != null) {
this.extensions.putAll(builder.extensions);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only point I don't like because the putAll method does not maintain the order

private final List<String> queryPath;
private final Map<String, Object> extensions;
private final List<String> queryPath = new ArrayList<>();
private final Map<String, Object> extensions = new HashMap<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One way to make this class consistent (in the field initializations part) is to initialize also the queryPath and the extensions (like I have done): this lead to the putAll problem that does not maintain the order of the keys. The other way is to remove this initialization. Let me know what do you think about it

Copy link
Member

Choose a reason for hiding this comment

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

Make it a ImmutableMap.of() under the covers

private final ImmutableMap<String, Object> extensions;

and then do this.extensions = ImmutableMap.of(builder.extensions)

If it was already a immutable map then its a smart coy - if not it keeps order - ImmutableMaps are like LinkedHashMap in that sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method ImmutableMap.of(Map<> map) does not exist so I used the ternary operator to initialize the extensions field with .copyOf() when the builder.extension is not null, otherwise the extensions is initialized with the .of() method

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Use ImmutableMap

@bbakerman bbakerman added this to the 20.0 milestone Nov 21, 2022
this.queryPath.addAll(builder.queryPath);
}

this.extensions = (builder.extensions != null) ? ImmutableMap.copyOf(builder.extensions) : ImmutableMap.of();
Copy link
Member

Choose a reason for hiding this comment

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

perfect

@bbakerman bbakerman merged commit 57eca2e into graphql-java:master Nov 25, 2022
@federicorispo federicorispo deleted the chore/fix-tostring-method-in-validationerror branch November 26, 2022 08:10
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.

Minor optimization for ValidationError#toString()

2 participants