Amplify-cli: Dynamo primary sort key

Created on 21 Nov 2018  路  21Comments  路  Source: aws-amplify/amplify-cli

Is your feature request related to a problem? Please describe.
amplify init and amplify push api commands don't allow for Dynamo tables to be created with a sort key.

Describe the solution you'd like
There was some discussion here of a possible solution but it doesn't seem to be implemented yet https://github.com/aws-amplify/amplify-cli/issues/56#issuecomment-416736520

Also discussed here https://github.com/aws-amplify/amplify-cli/pull/277#issuecomment-428690938

Something like this seems like it would work for my case of needing a sort key on a timestamp

type DeviceData @model {
  id: ID!
  timestamp: String! @sort
  value: String!
}

Describe alternatives you've considered
Not aware of any, would be open to anything since sort keys cannot be added to already created Dynamo tables.

feature-request graphql-transformer

Most helpful comment

This is definitely our most needed feature at the moment. Would it be feasible to support specifying multiple sort fields? Example: sorting on createdAt or updatedAt. Clients would then specify what sort type to use in their graphql query variables.

All 21 comments

I would like to second this request

Thank you for the note. This is a highly request feature and your feedback really helps us prioritize it. I will make sure this is included in discussions and will report back when I have more details.

Would just like add that our organization would also love to see this feature. As it currently stands, we're going to have to try manually modifying the cloudformation template that amplify creates in order to adjust the partition and sort keys.

@zjullion I think you can link into an existing table or manually create a table and write your own custom resolvers. It may be easier to just form your own dynamo tables and write the custom resolvers than trying to fiddle with the auto-generated CloudFormation template.

This is definitely our most needed feature at the moment. Would it be feasible to support specifying multiple sort fields? Example: sorting on createdAt or updatedAt. Clients would then specify what sort type to use in their graphql query variables.

I also have the same need to filter on createdAt or any other field, would be great to have that available soon.

+1 We also really need the feature.

Wanted to ping this ticket again. We are working on an RFC for custom indexes on @model types and would love to hear your feedback when it is posted to GH.

@mikeparisstuff would be great to have a way not only specify sort key but partition too.

+1 We really need the feature also

+1 It would be great to have this feature.

+1

+1

+1

What is the best temporary way to sort createdAt?

Looks like difficult to sort all data, so easy way to achieve this (not using console ) maybe making (dummy) table and connect it to the table which want to be sorted using @connection(name: String, keyField: String, sortField: String).

or add some kind of metafield to table and use it as a partition key and use createdAt as sort key. (in this case, have to add gsi from console and maybe have to add resolver.)

type Post @model {
    id: ID!
    title: String
    creaatedAt: AWSDateTime // sort-key
    metadata: MetaData  // partion-key
}
type MetaData {
    category: Category
}
enum Category { comedy news }

or use ElasticSearch for sorting.

How is this still not resolved? This seems like it should be trivial. We need to define 1 to many relationships (user videos) and require a sort key.

+1

Currently for sorting, I am getting the query back from the response in call back then creating my own sorting algorithm. I think sorting is a fundamental operation for database/querying, it might not be core, but it is used so much that it seems core. I rather not use this @index implementation to interfere with schemas that I am already satisfied with. To my benefit I am only returning at most 20 results. If it was 100's or 1000's of data to sort I would be in big problem. But sorting is needed. Would appreciate if some sorting mechanism would be provided out of the box for appsyncgraphql

We launched support for custom indexes today. You can find docs for the same out here - https://aws-amplify.github.io/docs/cli/graphql#key
Please let us know if you're still not able to solve your problem through this solution and we'll re-open this issue for you.

Awesome work! 馃憤

Thanks a lot waking up to this news, I will try it out asap.

Was this page helpful?
0 / 5 - 0 ratings