Which GraphQL resolver operation and parameters correctly retrieve all orders for user "123" sorted by orderDate descending?
hard🚀 Application Q9 of 15
DynamoDB - with Serverless
You want to fetch a list of orders for a user using AppSync and DynamoDB. The orders table has a partition key userId and sort key orderDate. Which GraphQL resolver operation and parameters correctly retrieve all orders for user "123" sorted by orderDate descending?
AUse Scan operation with filterExpression "userId = :uid" and expressionValues {":uid": {"S": "123"}}
BUse Query operation with keyConditionExpression "userId = :uid", expressionValues {":uid": {"S": "123"}}, and scanIndexForward false
CUse GetItem operation with key {"userId": {"S": "123"}}
DUse Query operation with keyConditionExpression "orderDate = :date" and expressionValues {":date": {"S": "123"}}
Step-by-Step Solution
Solution:
Step 1: Identify correct operation for partition key query
Query operation efficiently retrieves items by partition key userId.
Step 2: Use keyConditionExpression and parameters
keyConditionExpression "userId = :uid" with expressionValues specifying userId "123" is correct.
Step 3: Set scanIndexForward false for descending order
scanIndexForward false sorts results by sort key orderDate descending.
Final Answer:
Query with keyConditionExpression on userId and scanIndexForward false -> Option B
Quick Check:
Query by partition key with descending sort = A [OK]
Quick Trick:Use Query with scanIndexForward false for descending sort [OK]
Common Mistakes:
MISTAKES
Using Scan instead of Query for partition key
Using GetItem which fetches single item
Querying by sort key only
Master "with Serverless" in DynamoDB
9 interactive learning modes - each teaches the same concept differently