Open jewells07 opened 5 days ago
Which portion of your lambda is returning null? Are you saying the result of the mutation is null or ddb.get
is returning null?
In this function
function getUserId(otherTableId) {
const result = ddb.get({
key: { id: otherTableId },
tableName: 'OtherTable',
});
console.log('otherTableId', otherTableId);
if (!result || !result.Item) {
return 'null';
}
return result.Item.userId;
}
Actually it is a JavaScript resolver, not lambda
Ah, makes sense. I don't think @aws-appsync/utils/dynamodb
offers the functionality to set the tableName
in ddb.get
. I don't see this feature documented. I can check with the AppSync team to see if they offer this feature.
Yes, I have tried using __typename: 'OtherTable'
, and it does not work either. How can we perform CRUD operations on the other table within this mutation handler (JavaScript resolver)?
The resolver can only be attached to a single data source. You will need to use a pipeline resolver to use multiple data sources. https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers-js.html
It would look something like this:
.handler([
a.handler.custom({
entry: './OtherTable/getUserID.js',
dataSource: a.ref('OtherTable'),
}),
a.handler.custom({
entry: './Todo/createTodo.js',
dataSource: a.ref('Todo'),
}),
])
Environment information
Data packages
Description
Im using custom mutation with handler.
In
data/resource.ts
In
data/Todo/createTodo.js
I am encountering an issue where it consistently returns
'null'
. How can I retrieve the userId from another table in a custom mutation? Additionally, I attempted to throw an error usingreturn new Error('System not found');
, but it did not work. I also tried adding async/await, but it appears to be unsupported. I attemptedbut that did not resolve the issue either, which led me to add
'null'
as a string.I have granted the necessary permissions for AppSync logs, but I do not see any logs in CloudWatch. I have explored every possible solution that I am aware of, but the problem persists.