Closed ChristopheBougere closed 4 years ago
@ChristopheBougere You could use @key directive and specify your own primary key instead of using the default id primary key.
Oh that's interesting I totally missed that directive. So instead of having this:
type Customer @model {
id: ID!
email: String!
username: String
}
I would have this:
type Customer @model @key(fields: ["id"]) {
id: String!
email: String!
username: String
}
And I would need to generate the id from the frontend and pass it during the create mutation? That looks great, I am just wondering if this could be risky to generate the ID from the frontend?
Thanks for your help @kaustavghosh06
@ChristopheBougere the resolver only assigns a value to id
during create if it was not specified in the input. If you decide to control it, it works fine, that is something you can control, how you want to do it. I'd suggest that for database storage stick to uuidv4 and use shortid as an additional attribute and populate it from the "client" (API facade?). Since probably you'll need to query it I'd define a named @key
to have a GSI generated for it.
The main reason I suggest this, that it is much easier to hit a collision with shortid because of its lower entropy.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels for those types of questions.
Is your feature request related to a problem? Please describe. I am using GraphQL resource IDs in my app URL. However they aren't SEO friendly (UUID v4 is 36 chars). I would like to replace them by short IDs instead, but IDs are automatically generated on create mutations.
Describe the solution you'd like In my
schema.graphql
, I would like having the choice between let sayID
andShortID
types.Describe alternatives you've considered I thought about creating my own
ShortID
type, but in generated resolvers it seems to be using a$util.autoId()
function (see docs). I don't know how I could generate an ID without a VTL function. And I don't want to have custom functions for each of my resolvers.Additional context I am not sure this issue only depends on the Amplify team, maybe as well on AppSync team. But maybe this is already planned (because SEO is quite important when running in production), or someone has a great workaround ?