[ https://issues.apache.org/jira/browse/SLING-10485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17361711#comment-17361711 ]
Bertrand Delacretaz commented on SLING-10485: --------------------------------------------- ...maybe we need to provide our own complete implementations of a (validating) {{JSONScalar}} and (anything goes) {{ObjectScalar}}, instead of just helpers to convert types. > Helpers to convert GraphQL types in Object scalars > -------------------------------------------------- > > Key: SLING-10485 > URL: https://issues.apache.org/jira/browse/SLING-10485 > Project: Sling > Issue Type: Improvement > Components: GraphQL > Affects Versions: GraphQL Core 0.0.10 > Reporter: Bertrand Delacretaz > Priority: Minor > > Working on the > [sample-graphql-api|https://github.com/apache/sling-whiteboard/tree/master/remote-content-api/sample-graphql-api] > exposed the need for converting the Objects provided by the graphql-java > parser to our own types, if we want to continue hiding the graphql-java APIs > (which I think is good). > In that sample module (at commit c1c930ea), this query, which uses an > {{ObjectScalar}} for its {{input argument}}: > {code:java} > mutation { > command(lang: "echo", input: > {structuredJSONdata: > { > isSupported: true, > for: "things like this", > as: {json: "data"} > }, > moreData: { > isOk :true, > comment : "as well" > } > } > ) { > success > output > help > } > } > {code} > Outputs > {code:java} > { > "data": { > "command": { > "success": true, > "output": > "ObjectValue{objectFields=[ObjectField{name='structuredJSONdata', > value=ObjectValue{objectFields=[ObjectField{name='isSupported', > value=BooleanValue{value=true}}, ObjectField{name='for', > value=StringValue{value='things like this'}}, ObjectField{name='as', > value=ObjectValue{objectFields=[ObjectField{name='json', > value=StringValue{value='data'}}]}}]}}, ObjectField{name='moreData', > value=ObjectValue{objectFields=[ObjectField{name='isOk', > value=BooleanValue{value=true}}, ObjectField{name='comment', > value=StringValue{value='as well'}}]}}]}", > "help": "Echoes its input" > } > } > } > {code} > With the ObjectValue (from the [graphql-java language > package|https://github.com/graphql-java/graphql-java/tree/master/src/main/java/graphql/language]) > converted to String instead of JSON. > To fix this, the {{output}} field in that schema needs to use the {{Object}} > which the {{ObjectScalar}} from that module handles, but doing that causes a > JSON conversion error, as the Johnzon library that we use to convert the > query result to JSON doesn't know that {{ObjectValue}} type. > To avoid that issue I think we need to provide a helper that the > {{ObjectScalar}} can use to convert the input object to an API that Johnzon > understands and that's independent from the graphql-java APIs. > To test this, the {{input}} field should work for all types such as String, > Int, Float, Boolean, Arrays of those and JSON. > It even looks like arrays of heterogenous types are supported, this Mutation > works: > {code} > mutation { > command(lang: "echo", input: [12, 34.5, "testing", {some: "json"}]) { > success > output > help > } > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)