This is a similar question to this one, but since no one answered it I want to see if I can get some answers about it.
I am starting to explore graphql and amplify since firestore has some limitations that I consider to restrictive to my application. But I have come to this situation where I want to make a query with limited results and the outcome is not what I expected. My database has only 13 records. And I need to get 12 elements each time.
So, I if I run this query:
query MyQuery {
listItems(filter: {type: {eq: "ropa"}}) {
items {
price
status
type
id
name
}
nextToken
}
}
This will return 4 items with a type value that equals to "ropa". So far so good. But if I add a limit of 12, like this:
query MyQuery {
listItems(filter: {type: {eq: "ropa"}}, limit: 12) {
items {
price
status
type
id
name
}
nextToken
}
}
I will only get 3 of those results and a nextToken, so I will have to pass the same query again but this time with the nextToken value to get the last result.
What I understand that is happening, is that when you limit your results, the query first takes the amount of elements specified in your limit and filters them to match your query.
In a scenario where I have to get 12 elements to fill the screen every time I reach the end of the list, I would have to call this query multiple times and would have to device a workaround to fill a temporary list so when it makes it to 12 items then I push them into my array and so on. And if I add a sort direction or other filters, the results reduce and the process becomes more complicated and inefficient to my perspective.
Is this the only way to do so?