I'm not sure what I'm missing. When I query my DynamoDB table using custom Appsync_JS resolvers, the result data is always null, even though the Cloudwatch logs show that the items are being retrieved. Here are some pictures for reference. Can anyone spot the problem?
JS Resolver:
import { util } from '@aws-appsync/utils';
import * as ddb from "@aws-appsync/utils/dynamodb";
export function request(ctx) {
const { PK, limit = 20, nextToxen} = ctx.args;
return ddb.query({
query: {PK: {eq: "SUE#" + PK} },
limit,
nextToxen,
});
}
export function response(ctx) {
return ctx.result;
}
Cloudwatch log:
{
"logType": "AfterResponseFunctionEvaluation",
"path": [
"querySuE"
],
"fieldName": "querySuE",
"resolverArn": "arn:aws:appsyncxxxxxx",
"requestId": "xxxxxxxxx",
"context": {
"arguments": {
"PK": "zzzzz"
},
"result": {
"items": [
{
"createdAt": "2024-06-09T20:40:30.940Z",
"SK": "SUE#01HZZBPBEWXBCSMZMKG8MHF16Q",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
},
{
"createdAt": "2024-06-09T20:40:31.468Z",
"SK": "SUE#01HZZBPBZC6Q4WW003GQR1HXWC",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
}
],
"scannedCount": 2
},
"prev": {
"result": {
"items": [
{
"createdAt": "2024-06-09T20:40:30.940Z",
"SK": "SUE#01HZZBPBEWXBCSMZMKG8MHF16Q",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
},
{
"createdAt": "2024-06-09T20:40:31.468Z",
"SK": "SUE#01HZZBPBZC6Q4WW003GQR1HXWC",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
}
],
"scannedCount": 2
}
},
"stash": {},
"outErrors": []
},
"fieldInError": false,
"evaluationResult": {
"items": [
{
"createdAt": "2024-06-09T20:40:30.940Z",
"SK": "SUE#01HZZBPBEWXBCSMZMKG8MHF16Q",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
},
{
"createdAt": "2024-06-09T20:40:31.468Z",
"SK": "SUE#01HZZBPBZC6Q4WW003GQR1HXWC",
"PK": "SUE#zzzzz",
"_TYPE": "SUE",
"title": "ichbintitel"
}
],
"scannedCount": 2
},
"errors": [],
"parentType": "Query",
"graphQLAPIId": "xxxxxxxxx"
}
Solution:
".items" added in custom resolver
export function response(ctx) {
return ctx.result.items; //items added
}
AND ".array" added in resouce.ts
querySuE: a
.query()
.arguments({
PK: a.string().required(),
SK: a.string(),
})
.returns(a.ref("SuE").array()) //.array added
.handler(
a.handler.custom({
dataSource: "ExternalTableDataSource",
entry: "./querySuE.js",
})
).authorization(allow => [allow.publicApiKey()]),