aws-appsyncaws-aurora-serverlessaws-appsync-resolver

AppSync returns attribute values as null from AuroraDB


I am trying to implement Appsync with Aurora RDS. Get query returns response with all the attribute values as null. I think it is able to connect with the DB properly because I have seen some error when I deliberately misspelled the table name. I am not sure where the problem is. I tried the same implementation with Dynamodb and it worked fine. Is this some problem with resolver or something related to permissions?

Response looks like this:

Response:

{
  "data": {
    "getTest": {
      "id": null,
      "name": null,
      "surname": null
    }
  }
}

DB table description with:

id  int(11) 
name    text    
surname text

AppSync GraphQL schema is:

 type Query {
    getTest(id: ID!): Test
}

type Test {
    id: ID
    name: String
    surname: String
}

schema {
    query: Query
}

Request resolver:

{
    "version": "2018-05-29",
    "statements": [
        "select * from TestTable where id = '$ctx.args.id'"
    ]
}

Response resolver:

#if($ctx.error)
    $utils.error($ctx.error.message, $ctx.error.type)
#end
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])

Solution

  • I was able to fix my issue. The problem was with referencing the result in response resolver. It worked after adding another [0] to the result object.

    #if($ctx.error)
        $utils.error($ctx.error.message, $ctx.error.type)
    #end
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])