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
90 stars 77 forks source link

Feature Request: Addition of Sort Direction and Sort Key in SQL-Based GraphQL Schemas #2613

Open kekami opened 4 months ago

kekami commented 4 months ago

Describe the feature you'd like to request

I would like to request the addition of a feature to the amplify-category-api that allows users to specify a sort direction and sort key when querying data in SQL-based GraphQL schemas. Currently, the API does not support this functionality, which limits the flexibility and efficiency of data retrieval, especially for complex queries requiring sorted results.

Issues: • Lack of sorting capabilities leads to inefficient client-side data processing. • Increased complexity in handling sorted data on the frontend. • Amplify documentation does not provide guidance on implementing server-side sorting for SQL-based GraphQL schemas.

Describe the solution you'd like

I propose the implementation of a sortDirection and sortKey parameter within the query structure for SQL-based GraphQL schemas. This enhancement would enable users to specify the sorting criteria directly in their queries, allowing for more efficient data retrieval and processing.

Example Query:

query GetUsers {
  listUsers(sortDirection: created_at_ASC) {
    items {
      id
      username
      created_at
    }
  }
}

Implementation Details: • sortDirection: Accepts values such as ASC (ascending) and DESC (descending) to define the order of the results. • sortKey: Specifies the field by which the results should be sorted, such as created_at, username, etc.

Benefits: • Improved performance by reducing the need for client-side sorting. • Enhanced query flexibility and efficiency. • Simplified data handling in frontend applications.

Potential Impact: • This feature would provide a more robust querying mechanism, aligning with common GraphQL practices and user expectations. • It would significantly enhance the usability of the amplify-category-api for developers working with large datasets.

Describe alternatives you've considered

Attempting to use sortDirection currently results in:

{
  "data": {
    "listUsers": null
  },
  "errors": [
    {
      "path": [
        "listUsers"
      ],
      "data": null,
      "errorType": "InvalidArgumentsError",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "sortDirection is not supported for List operations without a Sort key defined."
    }
  ]
}

Additional context

No response

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

Would this feature include a breaking change?

AnilMaktala commented 4 months ago

Hey @kekami, Thanks for raising this. We are marking this as a feature request for the team to evaluate further.