Description
Page: /lib/datastore/getting-started/q/platform/js
Feedback:
It appears that in order to query the datastore you need an association table to retrieve the record you need.
For instance here is a GraphQL user profile where the profile id is the cognito user sub (3722f35e-de54-45b2-b26e-676e2cc48160) which makes the user profile easy to access by Auth.currentUserPoolUser()
schema looks like this:
type User @model {
id: ID!
username: String
userPhone: String
createdAt: String
updatedAt: String
}
user profile loaded into DataStore is
Object {
"createdAt": 1593774031,
"id": "3722f35e-de54-45b2-b26e-676e2cc48160",
"userPhone": "",
"username": "One Two",
}
let input = {
id: id,
username: username,
userPhone: userPhone,
createdAt: createdAt,
}
let myDataStore = await DataStore.save(new User({input}));
once it is saved to the Datastore it looks like this.
dataStore is User {
"_deleted": undefined,
"_lastChangedAt": undefined,
"_version": undefined,
"id": "f86d3252-7b1d-44f6-b4cd-b8a7a3a88def",
"input": Object {
"createdAt": 1593774031,
` "id": "3722f35e-de54-45b2-b26e-676e2cc48160",`
"userPhone": "",
"username": "One Two",
},
}
In order to query the Datastore and get this record I need to query the datastore with the datastore id:
DataStore.query(User, c => c.id("eq", "f86d3252-7b1d-44f6-b4cd-b8a7a3a88def"));
However the only way to know what the datastore id is to create another table that associates the datastore id with the user profile id which in this case is the user's cognito sub.
This does NOT work
DataStore.query(User, c => c.input.id("eq", "3722f35e-de54-45b2-b26e-676e2cc48160"));
This does NOT work
DataStore.query(User, c => c.id.id("eq", "3722f35e-de54-45b2-b26e-676e2cc48160"));
Is the recommended architecture to create an association table that connects a user's cognito sub with every associated datastore id or is there another way to access the properties of the datastore record?
I've read through the documentation and all of it seems to just explicitly pass the datastore record id which isn't all that helpful in practical use.
.
.