aws / aws/aws-appsync-community

toJsonObject Unrecognised by AppSync Tests

Open
#359 1 comment 0 reactions 0 assignees View on GitHub
bug pending triage
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/aws/aws-appsync-community/assets/971000/e41abe0c-889b-40fe-9d5c-cf43c4beda49)

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"
}
}`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the resolver in the AppSync Console Test using the provided request and response entry points, especially the toJsonObject(result) call. Compare the Console Test behavior with the normally working CDK execution and determine whether the runtime error is specific to the console context. Done means the discrepancy is reproduced and documented with the relevant execution context.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.