In an AppSync JavaScript resolver there is a strange bug where if I use the let keyword to define a default value and then conditonally change it, deployment fails (with a BadRequestException):
export function request(ctx) {
const { productCode } = ctx.args;
// We can look at the fields selected in the query and scope our DynamoDB query narrower if items are not requested
const { selectionSetList } = ctx.info;
// Default to the wider query (using ge) including items
let SK = { ge: `#PRODUCT#${productCode}` };
// And only narrow (using eq) to exclude items if the selectionSetList explicitly doesn't include itemSummaries
if (selectionSetList != null && !selectionSetList.includes('items')) {
SK = { eq: `#PRODUCT#${productCode}` };
}
// ...
}
Whereas if I use an if...else and avoid default initialization, it succeeds:
export function request(ctx) {
const { productCode } = ctx.args;
// We can look at the fields selected in the query and scope our DynamoDB query narrower if items are not requested
const { selectionSetList } = ctx.info;
let SK;
// Only narrow (using eq) to exclude items if the selectionSetList explicitly doesn't include itemSummaries
if (selectionSetList != null && !selectionSetList.includes('items')) {
SK = { eq: `#PRODUCT#${productCode}` };
} else {
// Otherwise default to the wider query (using ge) including items
SK = { ge: `#PRODUCT#${productCode}` };
}
// ...
}
In an AppSync JavaScript resolver there is a strange bug where if I use the
let
keyword to define a default value and then conditonally change it, deployment fails (with aBadRequestException
):Whereas if I use an
if...else
and avoid default initialization, it succeeds: