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 Antwort
0
Akzeptierte Antwort

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
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen