DebugFactor.com | Forum

AWS AppSync GraphQL query is returning only 20 records

I have an AppSync API with DynamoDB as a datasource. The application is built with AWS Amplify.

When I fetch the records from my DynamoDB table, I am getting only 20 records. I have more than 100 records on my table.

My react code to fetch the list is

const userList = await API.graphql(graphqlOperation(listUserDetails));

And my queries.js is

export const listUserDetails= /* GraphQL */ `
  query listUserDetails(
    $filter: TableUserDetailsFilterInput
    $limit: Int
    $nextToken: String
  ) {
    listUserDetails(filter: $filter, limit: $limit, nextToken: $nextToken) {
      items {
        USERID
        JOBID
        STATUS
        PROFILEIMAGE
      }
      nextToken
    }
  }
`;

There is a limit parameter seen in your listUserDetails graphql query. I suspect it is set to default 20 somewhere within your code, or within some library/dependency which you are using.

To override, just pass the list parameter when you invoke the query like this.

const userList = await API.graphql(graphqlOperation(listUserDetails, {limit: 1000}));

Note that DynamoDB has a limit on the amount of data it can send in one request. If you have planning to have thousands of data retrieved from your table, check out the pagination feature of DynamoDB.