1

I'm try to run queries to AWS AppSync to fetch all list of Todos which I got around 50 items in DynamonDB but the result only return 20 items in my web, is there any limitation for AppSync?

I used amplify library to run the query:

API.graphql(
        graphqlOperation(queries.listTodos)
    )

How could I get all the 50 items from my dynamoDB?

Query:

export const listTodos = `query ListTodos(
  $filter: TableTodoFilterInput
  $limit: Int
  $nextToken: String
) {
  listTodos(filter: $filter, limit: $limit, nextToken: $nextToken) {
    items {
      id
      dateIn
      dateOut
      reservedBy
      status
      ttl
      createdON
    }
    nextToken
  }
}
`;

Sample data:

"items": [
        {
          "id": "ad2ce180-eae4-4bbd-abbc-00375e2dabd9",
          "dateIn": "2019-03-13",
          "dateOut": "2019-03-16",
          "reservedBy": "Harith",
          "status": "Pending Payment",
          "ttl": 1552357596,
          "createdON": "2019-03-11T02:26:36.608Z"
        },
Mohammad Harith
  • 593
  • 1
  • 10
  • 22
  • 1
    can you provide the listTodos query? it might be because you filter some things in your query. Oh and can you provide a sample item for your db? It can also because of the query response size limit from dynamodb – kkesley Mar 11 '19 at 23:54
  • 1
    Also can you provide the request / response mapping template of the resolver for listTodos? It's possible that a limit is being set from the AppSync that might explain why only 20 are being returned. – Aaron_H Mar 12 '19 at 01:28

1 Answers1

3

In your listTodos resolver's Request mapping template probably has the following line:

"limit": $util.defaultIfNull(${ctx.args.limit}, 20), 

Change this limit to something other than 20, or make it really high if you don't want results to be limited. (Note: DynamoDB will automatically paginate once your result set reaches 1 MB.) However it's typically a good practice to have some kind of reasonable limit set for Scan operations, as a Scan operation can consume 100% of the provisioned read capacity of the table and throttle other requests to your table. This is especially important as your table grows in size, but for 50 records, this shouldn't be an issue.

Aaron_H
  • 1,623
  • 1
  • 12
  • 26
  • 1
    Thanks! I changed it to 10k and it seems to be working, based on my sample data. How much limit do you think I have before it get paginated? – Mohammad Harith Mar 12 '19 at 06:15
  • That depends on the size of the records you are storing. For example, if your records average 1 kB in size, you can expect to get around 1024 records before your results will be paginated (meaning you will get a nextToken in the response from DynamoDB). – Aaron_H Mar 13 '19 at 07:26
  • 3
    Also, do note that AppSync limits the VTL engine's forEach loop iterations to 1,000. So if you have more items than that returned by Dynamo, VTL will stop iterating through them after 1,000. In short, a limit argument higher than 1,000 will cease to return more results, so you should keep limit to 1,000 max and paginate further results. – Gabe Hollombe Jan 15 '20 at 03:01