Allow to set our proper ID when using DataStore and generated models
See original GitHub issueIt would be great to allow us to manage IDs ourself. I see already two case where built-in IDs management is not efficient.
UserID from Cognito (sub) How many devs wanted to save a User object with the sub as ID? But currently we can’t and need to save it as separate property with an index.
type User {
id: ID! # would be great sub from Cognito
address: String
}
Support of Union?
type Image {
id: ID!
name: String!
width: Int!
height: Int!
url: String!
}
type Video {
id: ID!
name: String!
lang: Lang!
resolutions: [Resolution!]!
url: String!
}
union Media = Image | Video
type Product {
id: ID!
name: String!
description: Media! @connection
}
By having the typename as prefix of the ID we could determine where to fetch the resource. This must be also with a Improvement of @connection amplify-cli#5129.
Shorter IDs? (more personal choice) Personally I like to have short and self descriptive IDs (using uniqid node package) like:
- img-XXXXX
- vid-YYYYY
- pdt-ZZZZZ
How can it be made? I suppose there we can also pass the typename and maybe get from the config a custom uuid factory. https://github.com/aws-amplify/amplify-js/blob/00d5e1773766dad5a1c04b70e2d6d72a42268796/packages/datastore/src/storage/adapter/AsyncStorageDatabase.ts#L32-L38
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:10 (2 by maintainers)
Top GitHub Comments
Any updates here? would be great to save a predefined ID for the model.
Docs on best practices/common patterns for Cognito User Pool “Users” <> Amplify DataStore “Users” would be great as well.
Currently, the field is a bit hazy in this topic.
username
? Do you query the DataStore first?id
for a customUser
DataStore
model? Currently, it’sreadonly
and you cannot update it.