-
Notifications
You must be signed in to change notification settings - Fork 96
Support non-object values for JSON scalars #2285
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
Conversation
Would it not be better to map the individual values ? So Array to Array, String to String etc ? @jmartisk ?? |
6b91978
to
7bc36b2
Compare
I uploaded a sample project with a few test cases, and I amended my commit to include separate mappings for the There are a couple of points that are unclear to me:
populateScalar("jakarta.json.JsonNumber", JSON, String.class.getName()); which seems to work, but I don't know if it is correct. |
populateScalar("jakarta.json.JsonObject", "JSON", Object.class.getName()); | ||
populateScalar("jakarta.json.JsonValue", JSON, Object.class.getName()); | ||
populateScalar("jakarta.json.JsonString", JSON, String.class.getName()); | ||
populateScalar("jakarta.json.JsonNumber", JSON, String.class.getName()); |
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.
Should number not map to a java Number ? and Array to Array ?
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.
I tried
populateScalar("jakarta.json.JsonNumber", JSON, Number.class.getName());
populateScalar("jakarta.json.JsonArray", JSON, Object[].class.getName());
and got no errors (also, I saw no difference in the query response).
To be honest, I'm having a hard time tracking where this third argument is actually used.
I see it used in io.smallrye.graphql.execution.Classes.isNumberLikeType
, but that method will return false for Number
. Maybe we should use BigDecimal
instead?
I also see it used for io.smallrye.graphql.execution.datafetcher.helper.AbstractHelper.shouldTransform
, but that method will return true for any value other than jakarta.json.JsonNumber
itself.
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.
Lets wait for @jmartisk to 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.
TBH I don't see much value in separately registering JsonString
, JsonNumber
, etc. How about simply supporting JsonValue
and JsonObject
? If one wanted to have a string field, they would simply use String
, not JsonString
IMO.
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.
To be honest, I'm having a hard time tracking where this third argument is actually used.
Same here TBH, this was written a long time ago and not by me.
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.
TBH I don't see much value in separately registering JsonString, JsonNumber, etc. How about simply supporting JsonValue and JsonObject?
That's understandable. JsonValue
pretty much covers everything, and keeping JsonObject
would avoid any breaking changes. Should I remove the rest?
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.
I removed most of the added registrations and kept only the addition of JsonValue
.
Extend support for JSON scalars, to include not only JSON objects, but also any other JSON value, like strings, numbers and arrays.
2319f37
to
1d46a8e
Compare
@jmartisk Any reason the wildfly feature pack build fails ? |
Sorry for the delay, looking into it again today. |
I can get |
E.g. if you want to pass an array of strings, you can use
rather than
That's a little inconvenient, and it's not as shown in the graphql-java-extended-scalars readme. A simple workaround I tried is mapping the |
Ah, I was trying to use a value like Generally, it seems that passing a JSON array doesn't work as input (but this can be worked around by making the operation accept I'm not sure what exactly we would have to do to accept these values as |
Perhaps we could add a special transformation that constructs a |
I'm not sure I understand the distinction you draw between the handling of JSON objects and arrays. Unless I'm mistaken, neither really "work" as inputs. For objects, I would expect to be able to pass:
which doesn't work. The following works, but it isn't quite right:
|
A json array is a valid
Let's not get into that hole please :D |
I suppose that you mean: |
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.
Let's merge this, it's definitely a good start, even though it has a few shortcomings. Thanks!
Extend support for JSON scalars, to include not only JSON objects, but also any other JSON value, like strings, numbers and arrays.