Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toJsonObject Unrecognised by AppSync Tests #359

Open
monscamus opened this issue Apr 9, 2024 · 1 comment
Open

toJsonObject Unrecognised by AppSync Tests #359

monscamus opened this issue Apr 9, 2024 · 1 comment
Labels
bug Something isn't working pending triage Pending further investigation

Comments

@monscamus
Copy link

monscamus commented Apr 9, 2024

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
Copy link
Author

Additionally the toJsonObject ignores field aliasing and constructs the JSON based on the underlying field name. This is breaking behaviour as it is exceptionally useful to rename returns from the SQL/Stored Procedure.

e.g. SELECT ee.firstname as firstName [whether you include `` around the alias]

is mapped as "firstname": "value" by toJsonObject which is highly undesirable.

@onlybakam onlybakam added bug Something isn't working pending triage Pending further investigation labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage Pending further investigation
Projects
None yet
Development

No branches or pull requests

2 participants