Open godrimcom opened 2 months ago
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
Hey @godrimcom, Thank you for bringing this up. Could you please clarify if you have already reviewed the relevant documentation on this topic?
Hi @godrimcom At the moment there is no way, at least that I'm aware of, to access and pass the table name to a resolver without incurring a "circular dependency" error. You may have to hard code the table name and pass it as an environment variable.
ex:
backend.data.resources.cfnResources.cfnGraphqlApi.environmentVariables = {
TODO_TABLE:
// replace with your own table name
`Todo-md4n36jl7za7xi4mie3cs3wyey-NONE`,
};
in the resolver you'd access environment variables from the context:
import { util } from "@aws-appsync/utils";
export const request = (ctx) => {
const todos = [];
ctx.args.todos.forEach(({id}) => {
todo.push(util.dynamodb.toMapValues({ id }));
});
return {
operation: "BatchGetItem",
tables: {
[ctx.env.TODO_TABLE]: {
keys: todos,
},
},
};
};
export const response = (ctx) => {
return ctx.result.data[ctx.env.TODO_TABLE];
};
we are working on a way to make the DDB tables accessible.
UPDATE: You can also compute the name of the table because it will be in the format <model>-<apiId>-<environment>
.
I'm not sure what determines <environment>
, in my sandbox environment it's set to NONE
, hence the table name "Todo-md4n36jl7za7xi4mie3cs3wyey-NONE"
Hi @chrisbonifacio , just checking that you know you can access the table name from the data resources. So
const { tables } = backend.data.resources
backend.data.resources.cfnResources.cfnGraphqlApi.environmentVariables = {
TODO_TABLE: tables['Todo'],
};
Environment information
Description
I'm using amplify gen 2 and I added a custom handler in my schema:
this is my handler:
I just want to do a BatchDeleteItem operation. This should be a basic operation, please help