aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
88 stars 76 forks source link

Feature Request: Addition of totalCount to list queries using SQL Schemas. #2611

Open kekami opened 3 months ago

kekami commented 3 months ago

Describe the feature you'd like to request

I would like to request the addition of a totalCount field to the list***** queries in the amplify-category-api when using SQL Schema. Currently, when querying, we receive the limit, nextToken, filter, and items fields, but there is no way to know the total number of items that match the query criteria. Adding totalCount would provide this crucial piece of information, enhancing the ability to manage and paginate data more effectively.

I understand that totalCount is not possible in DDB schemas, but it would be nice if SQL schema could support this.

Describe the solution you'd like

The solution would involve modifying the listUsers query schema to include a totalCount field. This field should return the total number of users that match the query criteria, irrespective of the limit applied. An example of the updated query would be:

query GetUsers {
  listUsers {
    limit
    nextToken
    totalCount
    items {
      id
    }
  }
}

With this enhancement, a typical response would look like:

{
  "data": {
    "listUsers": {
      "limit": 10,
      "nextToken": "abc123",
      "totalCount": 150,
      "items": [
        { "id": "1" },
        { "id": "2" },
        ...
      ]
    }
  }
}

This change would greatly improve the usability of the API for applications that need to display or process large lists of users, enabling more informed pagination and data handling strategies.

Describe alternatives you've considered

The only option that I see is to recreate all list queries by myself and not make use of the autogenerated queries, which is a bit of an overhead.

Additional context

No response

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

AnilMaktala commented 3 months ago

Hey @kekami, Thanks for raising this. is it for Gen1 or Gen2?

kekami commented 3 months ago

Hey @kekami, Thanks for raising this. is it for Gen1 or Gen2?

Hi, for Gen2.