Environment information
System:
OS: macOS 15.3.1
CPU: (8) arm64 Apple M1
Memory: 151.67 MB / 8.00 GB
Shell: /bin/zsh
Binaries:
Node: 23.1.0 - /opt/homebrew/bin/node
Yarn: 1.22.22 - ~/.yarn/bin/yarn
npm: 10.9.0 - /opt/homebrew/bin/npm
pnpm: undefined - undefined
NPM Packages:
@aws-amplify/auth-construct: 1.5.1
@aws-amplify/backend: 1.10.0
@aws-amplify/backend-auth: 1.4.2
@aws-amplify/backend-cli: 1.4.4
@aws-amplify/backend-data: 1.2.3
@aws-amplify/backend-deployer: 1.1.12
@aws-amplify/backend-function: 1.10.0
@aws-amplify/backend-output-schemas: 1.4.0
@aws-amplify/backend-output-storage: 1.1.4
@aws-amplify/backend-secret: 1.1.4
@aws-amplify/backend-storage: 1.2.4
@aws-amplify/cli-core: 1.2.1
@aws-amplify/client-config: 1.5.4
@aws-amplify/deployed-backend-client: 1.5.0
@aws-amplify/form-generator: 1.0.3
@aws-amplify/model-generator: 1.0.10
@aws-amplify/platform-core: 1.4.0
@aws-amplify/plugin-types: 1.6.0
@aws-amplify/sandbox: 1.2.8
@aws-amplify/schema-generator: 1.2.6
aws-amplify: 6.10.3
aws-cdk: 2.173.2
aws-cdk-lib: 2.173.2
typescript: 5.7.2
Data packages
├─┬ @aws-amplify/backend-cli@1.4.4
│ └─┬ @aws-amplify/schema-generator@1.2.6
│ └── @aws-amplify/graphql-schema-generator@0.11.3
└─┬ @aws-amplify/backend@1.10.0
└─┬ @aws-amplify/backend-data@1.2.3
└── @aws-amplify/data-construct@1.14.3
Description
amplify/data/BatchCreateTestAreaHandler.js
export function request(ctx) {
var now = util.time.nowISO8601()
console.log('Context: ', ctx)
return {
operation: 'BatchPutItem',
tables: {
[`TestArea-${ctx.stash.awsAppsyncApiId}-${ctx.stash.amplifyApiEnvironmentName}`]: ctx.args.testArea.map(
(testArea) =>
util.dynamodb.toMapValues({
...testArea,
id: util.autoId(),
createdAt: now,
updatedAt: now,
}),
),
},
}
}
amplify/data/resource.ts
TestArea: a
.model({
id: a.id(),
name: a.string(),
place: a.string(),
featureType: a.enum(['place', 'postcode', 'district', 'region']),
})
.authorization((allow) => [allow.owner(), allow.group('admin'), allow.guest().to(['read'])]),
BatchCreateTestArea: a
.mutation()
.arguments({
testAreas: a.json().array(),
})
.handler(
a.handler.custom({
dataSource: a.ref('TestArea'),
entry: './BatchCreateTestAreaHandler.js',
}),
)
.returns(a.ref('TestArea').array())
.authorization((allow) => [allow.group('admin')]),
usage
const { data, errors } = await client.mutations.BatchCreateTestArea({
testAreas: [
'{"name":"Austin","featureType":"place","place":"Texas, United States"}',
'{"name":"San Jose","featureType":"place","place":"California, United States"}',
],
})
Cloudwatch
"context": {
"arguments": {
"testAreas": []
},
"prev": {
"result": {}
},
"stash": {},
"outErrors": []
},
Don't mind if there's a typo somewhere, i modified the model slightly for the issue.
The issue i'm facing is that whenever i invoke the mutation, it's not giving me the testAreas in the ctx.args as mentioned in the doc and also i do not get awsAppSyncApiId and amplifyApiEnvironmentName from ctx. I had to manually add it to the resolver code in AppSync.
What is the issue here?
Environment information
Data packages
Description
amplify/data/BatchCreateTestAreaHandler.jsamplify/data/resource.tsusageCloudwatchDon't mind if there's a typo somewhere, i modified the model slightly for the issue.
The issue i'm facing is that whenever i invoke the mutation, it's not giving me the testAreas in the ctx.args as mentioned in the doc and also i do not get awsAppSyncApiId and amplifyApiEnvironmentName from ctx. I had to manually add it to the resolver code in AppSync.
What is the issue here?