How to return all records with a single AWS AppSync List Query?

0

Hi all, my AWS AppSync list query is not returning all the records from DynamoDB table after applying a filter.

For context, I have a table with all major Cities with approximately 250k records. When I filter the table to show only cities in, for example, United Kingdom, the query does not return all records because AppSync will limit the scan operations to 10 items. If I then add a limit variable of 1,000 to the query I get less than 1,000 cities in the UK. It appears that the query first applies the limit before the filter and not the other way round for some reason...

I know I could use the next token as outline in AppSync Query Returns Wrong Item Numbers AWS Blog. However this means I'll have to perform multiple calls. Is there a way to return all filtered cities with a single AppSync query? Thanks in advance!

1 個回答
0
已接受的答案

I thought of sharing my approach to this, I used a Global Secondary Key (GSI) in the CITY table so I could query the cities by country_code (see below). I then used pagination to gather the remaining cities since the API does not return more than 1MB of data. I really like this video from YouTube that explains the difference between Scan and Query for those that are just getting started.

type CITY @model {
id: ID!
country_code: String! @index(name: "byCountry", queryField: "listCitiesbyCountry")
name: String!
code: String!
state: String
...
}
jesusER
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南