Bird
0
0

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:
  1. Step 1: Identify correct operation for partition key query

    Query operation efficiently retrieves items by partition key userId.
  2. Step 2: Use keyConditionExpression and parameters

    keyConditionExpression "userId = :uid" with expressionValues specifying userId "123" is correct.
  3. Step 3: Set scanIndexForward false for descending order

    scanIndexForward false sorts results by sort key orderDate descending.
  4. Final Answer:

    Query with keyConditionExpression on userId and scanIndexForward false -> Option B
  5. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes