You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Bertrand Delacretaz (Jira)" <ji...@apache.org> on 2021/06/11 12:27:00 UTC

[jira] [Created] (SLING-10485) Helpers to convert GraphQL types in Object scalars

Bertrand Delacretaz created SLING-10485:
-------------------------------------------

             Summary: 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


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, this query:

{code}
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}
{
  "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]) is converted to String instead of JSON.

To fix this, the {{output}} field in that schema needs to use the {{Object}} type to use the {{ObjectScalar}} from that module, 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)