My DynamoDB table data schema:
PartitionKey: "PK" -> String
SortKey: "SK" -> Number (timestamp)
Attribute: "Summary" -> JsonMap
My main usecase is that I have a "PK" and the range of "SK", which is the target time range, and query DDB to get a list of "Summaries". This data design is good for DDB APIs.
Now, I want to use AppSync to create a GraphQL API for this DynamoDB for a Amplify app. So I create a GraphQL schema like this:
type DataSummary {
PK: String!
SK: Float!
Summary: AWSJSON
}
GraphQL automatically creates 2 query APIs for me: getDataSummary
and listDataSummary
. What supperises me is, when I do list API, I can use filter to define the query as:
query listDataSummaries {
listDataSummaries(filter: {PK: {eq: "##Some key string##}"}, SK: {gt: ##Some timestamp##}}) {
items {
PK
SK
Summary
}
}
}
But, the return value is "null" because of paginating, which means GraphQL is doing a table scan to gather all items in the table and then does a filter based on my request. This is against my table design because it requires significantly more RCUs than a normal DDB API call for the same result. So, what did I miss? How can I "ask" GraphQL to do a DDB query instead of a scan for PK/SK list operation?