0

I need a GraphQL query returning hardcoded informations as JSON response.

In the AppSync GraphQL schema, I added the following query:

type Query {
  getHealthCheck: AWSJSON
}

My response mapping template where the values are hardcoded is the following:

$util.toJson({"version": "0.1.0"})

However, as the response of the query, I get a string instead of a proper JSON, i.e.:

{
    "data": {
        "getHealthCheck": "{\"version\":\"0.1.0\"}"
    }
}

How can I modify the response mapping template to get a proper JSON? I tried several utils but I'm a bit lost with the data structures in VTL.

bolino
  • 867
  • 1
  • 10
  • 27

1 Answers1

1

I don't think this is possible.

If you think about it, it goes against the idea of even having a GraphQL schema to then return essential arbritrary JSON.

I believe that AWSJSON will parse stringified JSON for inputs, but serialize to stringified JSON for outputs.

There's an answer to an other question that might give some ideas of how to work around this. Other than that, it seems your client will need to parse the JSON.

Zac Charles
  • 1,208
  • 14
  • 19