Peter
Peter

Reputation: 788

AWS AppSync RDS - Passthrough output resolver for json SQL result

Is it possible to create some sort of passthrough response resolver for an RDS datasource. The result of the query is 1 row and 1 column of type json which I would like to be the result of the graphql query.

Eg. schema could be

type Query {
    getJsonFromDb(p: String): Res
}

type Res {
  prop: String
}

schema {
    query: Query
}

The request resolver could be

{
    "version": "2018-05-29",
    "statements": [
        "select json_build_object('prop',:P)"
    ],
    "variableMap": {
        ":P": $util.toJson($ctx.arguments.p)
    }    
}

In the log result logging looks like this

"result": "{\"sqlStatementResults\":[{\"columnMetadata\":[{\"arrayBaseColumnType\":0,\"isAutoIncrement\":false,\"isCaseSensitive\":true,\"isCurrency\":false,\"isSigned\":false,\"label\":\"json_build_object\",\"name\":\"json_build_object\",\"nullable\":0,\"precision\":2147483647,\"scale\":0,\"schemaName\":\"\",\"tableName\":\"\",\"type\":1111,\"typeName\":\"json\",\"signed\":false,\"autoIncrement\":false,\"caseSensitive\":true,\"currency\":false}],\"numberOfRecordsUpdated\":0,\"records\":[[{\"stringValue\":\"{\\\"prop\\\" : \\\"test\\\"}\"}]]}]}"

So it's there allright, but I cannot seem to find the correct velocity expressions to get it out.

All tips certainly appreciated!

Peter

Upvotes: 0

Views: 322

Answers (1)

Peter
Peter

Reputation: 788

So I found one way of getting this done by doing like in the response mapping

$util.parseJson($ctx.result).sqlStatementResults[0].records[0][0].stringValue

Upvotes: 1

Related Questions