#TableName in Custom JS Resolvers

4 messages · Page 1 of 1 (latest)

steel dock
#

The amplify docs talk about using transactions in custom resolvers, but they don't talk about how to get the generated tablenames into said resolvers. If I try:

backend.data.resources.cfnResources.cfnGraphqlApi.addPropertyOverride(
  "EnvironmentVariables",
  {
    USER_TABLE_NAME: backend.data.resources.tables.User.tableName,
    API_ID: backend.data.apiId,
  }
);

It will fail because of a circular dependency whether I try passing either the tableName or the apiId.
So how are we supposed to do make batch requests or transactions without knowing the tablenames?

steel dock
#

Are transactions no possible in Amplify?? If not, you should mention that as a very clear limitation, not tempting their possibility in the docs

past oak
#

You can try something like this in your resolver: User-${ctx.stash.awsAppsyncApiId}-NONE

steel dock
#

OH! THANK YOU.
I had no idea that appsync was injecting that into the stash as a part of the resolvers in custom pipelines. But upon further inspection, you're absolutely right:

/**
 * Pipeline resolver request handler
 */
export const request = (ctx) => {
    ctx.stash.awsAppsyncApiId = '<apiId>';
    ctx.stash.amplifyApiEnvironmentName = 'NONE';
    return {};
};
/**
 * Pipeline resolver response handler
 */
export const response = (ctx) => {
    return ctx.prev.result;
};