question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to set our proper ID when using DataStore and generated models

See original GitHub issue

It 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:open
  • Created 3 years ago
  • Reactions:9
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
nitemarketcommented, Feb 6, 2021

Any updates here? would be great to save a predefined ID for the model.

2reactions
thiskevinwangcommented, Dec 31, 2020

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.

  • How do you specify a unique user-specified username? Do you query the DataStore first?
  • (Reiterating the original ask) How/can you pass a cognito-sub as the id for a custom User DataStore model? Currently, it’s readonly and you cannot update it.
  • etc.
Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Amplify allows you to mix and match authorization ...
With today's release, Amplify DataStore gains the ability to configure multiple authorization modes for a single app data backend.
Read more >
DataStore - Getting started - JavaScript - AWS Amplify Docs
DataStore relies on code generation to guarantee schemas are correctly converted to platform code. Like the initial setup, models can be generated either...
Read more >
App Architecture: Data Layer - DataStore - Android Developers
Preferences DataStore and Proto DataStore · Preferences DataStore stores and accesses data using keys. This implementation does not require a ...
Read more >
Datastore Overview | Cloud Datastore Documentation
The consistency models allow your application to deliver a great user experience ... scales with the size of the result set (as opposed...
Read more >
Set up service authentication - Azure Machine Learning
To access the workspace ACR, create machine learning compute cluster with system-assigned managed identity enabled. You can enable the identity ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found