Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ exports[`has many references with partition key + sort key 1`] = `
},
\\"expressionValues\\": {
\\":partitionKey\\": $util.dynamodb.toDynamoDB($partitionKeyValue),
\\":sortKey\\": $util.dynamodb.toDynamoDB(\\"\${sortKeyValue0}\\")
\\":sortKey\\": $util.dynamodb.toDynamoDB($sortKeyValue0)
}
} )
#set( $args = $util.defaultIfNull($ctx.stash.transformedArgs, $ctx.args) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const PARTITION_KEY_VALUE = 'partitionKeyValue';
export class DDBRelationalResolverGenerator extends RelationalResolverGenerator {
makeExpression = (keySchema: any[], connectionAttributes: string[]): ObjectNode => {
if (keySchema[1] && connectionAttributes[1]) {
let condensedSortKeyValue;
let condensedSortKeyValue = `$${SORT_KEY_VALUE}0`;

if (connectionAttributes.length > 2) {
const rangeKeyFields = connectionAttributes.slice(1);

condensedSortKeyValue = rangeKeyFields
condensedSortKeyValue = `"${rangeKeyFields
.map((keyField, idx) => `\${${SORT_KEY_VALUE}${idx}}`)
.join(ModelResourceIDs.ModelCompositeKeySeparator());
.join(ModelResourceIDs.ModelCompositeKeySeparator())}"`;
}

return obj({
Expand All @@ -69,7 +69,7 @@ export class DDBRelationalResolverGenerator extends RelationalResolverGenerator
}),
expressionValues: obj({
':partitionKey': ref(`util.dynamodb.toDynamoDB($${PARTITION_KEY_VALUE})`),
':sortKey': ref(`util.dynamodb.toDynamoDB(${condensedSortKeyValue ? `"${condensedSortKeyValue}"` : `$${SORT_KEY_VALUE}0`})`),
':sortKey': ref(`util.dynamodb.toDynamoDB(${condensedSortKeyValue})`),
}),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export class DDBRelationalReferencesResolverGenerator extends DDBRelationalResol
// #set( $sortKeyValue1 = <pk sk 1>
// These variables are then used in the query object as
// ":sortKey": $util.dynamodb.toDynamoDB("${sortKeyValue0}#${sortKeyValue1}"")
const condensedSortKeyValue = rangeKeyFields
.map((key, idx) => `\${${SORT_KEY_VALUE}${idx}}`)
.join(ModelResourceIDs.ModelCompositeKeySeparator());
const condensedSortKeyValue =
rangeKeyFields.length === 1
? `$${SORT_KEY_VALUE}0`
: `"${rangeKeyFields.map((key, idx) => `\${${SORT_KEY_VALUE}${idx}}`).join(ModelResourceIDs.ModelCompositeKeySeparator())}"`;

return obj({
expression: str('#partitionKey = :partitionKey AND #sortKey = :sortKey'),
Expand All @@ -69,7 +70,7 @@ export class DDBRelationalReferencesResolverGenerator extends DDBRelationalResol
}),
expressionValues: obj({
':partitionKey': ref(`util.dynamodb.toDynamoDB($${PARTITION_KEY_VALUE})`),
':sortKey': ref(`util.dynamodb.toDynamoDB("${condensedSortKeyValue}")`),
':sortKey': ref(`util.dynamodb.toDynamoDB(${condensedSortKeyValue})`),
}),
});
}
Expand Down