You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
npm list @aws-amplify/data-construct @aws-amplify/graphql-schema-generator
Description
Currently, I am unable to sort data based on multiple keys or specify which key should be used for sorting in GraphQL queries. While it's possible to create indexes with sort keys, the approach is restrictive and requires separate indexes for each sorting field, which becomes cumbersome and unscalable.
Use Case
My application requires sorting ticket data based on different fields in ascending or descending order, depending on the query. These fields include:
createdAt
totalPurchaseAmount
ticketRedemptionDateTime
Approach Taken
I attempted to create separate indexes and query fields for each sort key, as shown below:
Destructive : Adding new fields for sorting requires creating additional indexes and query fields, which leads to significant redundancy and this is destructive operation.
Single Key Limitation: Each query can only sort by one key at a time, even if multiple sort keys are declared.
Lack of Flexibility: I cannot dynamically specify the sorting field or direction (ascending/descending) without creating new indexes.
Expected Behavior
The ability to dynamically sort data by specifying the field and direction in the query (e.g., createdAt, totalPurchaseAmount, or ticketRedemptionDateTime).
Support for specifying sort direction (asc or desc) at runtime.
A scalable approach to sorting that avoids the need for creating separate indexes for each field.
Steps to Reproduce
Define multiple indexes with sort keys in the schema, as shown above.
Attempt to sort data by dynamically specifying a key or direction in a GraphQL query.
Observe that sorting is only possible for predefined keys and requires separate queries.
Environment
Backend: Using GraphQL with auto-generated queries and custom indexes.
Use Case: Ticket management system with sorting requirements based on purchase amount, creation time, and redemption time.
The text was updated successfully, but these errors were encountered:
Hi @amirpoudel 👋 thanks for raising this issue. Unfortunately, it's not possible to independently apply a sortDirection to each of these fields. This is a limitation of how DynamoDB handles sort keys and is outside of the control of either Amplify or AppSync.
Please see this comment on GitHub for an explanation. Note - that particular issue deals with filtering, not sorting, but the underlying cause is the same.
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
Environment information
Data packages
Description
Currently, I am unable to sort data based on multiple keys or specify which key should be used for sorting in GraphQL queries. While it's possible to create indexes with sort keys, the approach is restrictive and requires separate indexes for each sorting field, which becomes cumbersome and unscalable.
Use Case
My application requires sorting ticket data based on different fields in ascending or descending order, depending on the query. These fields include:
Approach Taken
I attempted to create separate indexes and query fields for each sort key, as shown below:
**index('type').sortKeys(['createdAt']).queryField("listTicketByTypeCreatedAt"),
index('type').sortKeys(['ticketRedemptionDateTime']).queryField("listTicketByTypeRedemptionDateTime"),
index('type').sortKeys(['totalPurchaseAmount']).queryField("listTicketByTypeTotalPurchaseAmount"),
index('eventId').sortKeys(['createdAt']).queryField("listTicketByEventIdCreatedAt"),
index('eventId').sortKeys(['totalPurchaseAmount']).queryField("listTicketByEventIdTotalPurchaseAmount"),
index('eventId').sortKeys(['ticketRedemptionDateTime']).queryField("listTicketByEventIdRedemptionDateTime"),
index('organizerId').sortKeys(['createdAt']).queryField("listTicketByOrganizerIdCreatedAt"),
index('organizerId').sortKeys(['totalPurchaseAmount']).queryField("listTicketByOrganizerIdTotalPurchaseAmount"),
index('organizerId').sortKeys(['ticketRedemptionDateTime']).queryField("listTicketByOrganizerIdRedemptionDateTime"),**
Problems with the Current Implementation
Destructive : Adding new fields for sorting requires creating additional indexes and query fields, which leads to significant redundancy and this is destructive operation.
Single Key Limitation: Each query can only sort by one key at a time, even if multiple sort keys are declared.
Lack of Flexibility: I cannot dynamically specify the sorting field or direction (ascending/descending) without creating new indexes.
Expected Behavior
The ability to dynamically sort data by specifying the field and direction in the query (e.g., createdAt, totalPurchaseAmount, or ticketRedemptionDateTime).
Support for specifying sort direction (asc or desc) at runtime.
A scalable approach to sorting that avoids the need for creating separate indexes for each field.
Steps to Reproduce
Define multiple indexes with sort keys in the schema, as shown above.
Attempt to sort data by dynamically specifying a key or direction in a GraphQL query.
Observe that sorting is only possible for predefined keys and requires separate queries.
Environment
Backend: Using GraphQL with auto-generated queries and custom indexes.
Use Case: Ticket management system with sorting requirements based on purchase amount, creation time, and redemption time.
The text was updated successfully, but these errors were encountered: