aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

toJsonObject Unrecognised by AppSync Tests

Open monscamus opened this issue 10 months ago • 1 comments

We have started converting our VTL resolvers to JS resolvers. When run in with CDK they appear to work. When we want to try out new ones or debug, we tried using the in Console Test for a simple resolver but toJsonObject seems to throw a runtime error:

import { sql, createMySQLStatement, toJsonObject } from '@aws-appsync/utils/rds';

export function request(ctx) {
    const query = sql`
    select
    uuid as id,
    name as name,
    tab_id as groupId,
    enforce_ordering as enforceOrder,
    DATE_FORMAT(created, '%Y-%m-%dT%H:%i:%s.000Z') as created,
    DATE_FORMAT(modified, '%Y-%m-%dT%H:%i:%s.000Z') as modified
    from bundles_bundle
    WHERE uuid=${ctx.args.id}`
    
    return createMySQLStatement(query);
  }

export function response(ctx) {
    const { error, result } = ctx;
    if (error) {
        return util.appendError(
            error.message,
            error.type,
            result
        )
    }
    return toJsonObject(result)[0][0]
}

image

With a normally working execution context. { "arguments": { "id": "b16d57a4-0240-4d2b-aa1c-fb3866a554fe", "batchId": "ACjXZpufRbwAU9h9PnMZFoRARaa1ximM" }, "env": {}, "source": { "task": "{\"key\":\"value\"}" }, "result": { "id": "EGKiGDy8rJ1vxCvjM21wOTQ646Bf0Lkr", "name": "Hello, world!", "enforceOrder": true, "requestId": "aB0W8lF7R125SN6YfnLHlCRoAeDpEhmo", "created": "1970-01-01T12:30:00.000Z", "modified": "1970-01-01T12:30:00.000Z" }, "identity": { "sub": "uuid", "issuer": "https://cognito-idp.{region}.amazonaws.com/{userPoolId}", "username": "my-username", "claims": {}, "sourceIp": [ "x.x.x.x" ], "defaultAuthStrategy": "ALLOW" } }

monscamus avatar Apr 09 '24 16:04 monscamus