-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update ValidationError#toString to print the extentions field #3024
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
Update ValidationError#toString to print the extentions field #3024
Conversation
- 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
…eryPath and extensions fields
….com:federicorispo/graphql-java into chore/fix-tostring-method-in-validationerror
| } | ||
|
|
||
| if (builder.extensions != null) { | ||
| this.extensions.putAll(builder.extensions); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
bbakerman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ImmutableMap
| this.queryPath.addAll(builder.queryPath); | ||
| } | ||
|
|
||
| this.extensions = (builder.extensions != null) ? ImmutableMap.copyOf(builder.extensions) : ImmutableMap.of(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect
toStringmethod inValidationErrorclass to print theextensionsfield. If the field is null then an empty array will be printed...extensions=[]messagefield because it was always initialized with the description but the getMessage() method is still there and returns the content of the descriptionextensionsandqueryPathfields during their declaration to align with thesourceLocationsfieldIt resolves #3005