-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feedback]Datastore documentation is lacking. #2102
Comments
I'm just getting to grips with DataStore myself, but shouldn't the query by
I found this documented in the DataStore.query API Reference but it should definitely also be mentioned in the Manipulating Data page in the Library documentation. #1903 already has a lot of work on revamping the DataStore docs - perhaps this could be added in. |
@j1mr10rd4n thanks I will give that a shot. |
Thanks for taking the time to provide this feedback @SeanRenet ! I've asked @manueliglesias to process this feedback. |
+1 request to improve DS Docs: #2077 |
@SeanRenet If your User object needs to be flat like you have in the schema you've defined, I wouldn't pass {
input: {
"createdAt": 1593774031,
"id": "3722f35e-de54-45b2-b26e-676e2cc48160",
"userPhone": "",
"username": "One Two",
}
} That doesn't match the shape of the schema you've defined, since there's no type User @model {
id: ID!
userSub: String
username: String
userPhone: String
createdAt: String
updatedAt: String
} And this app code: const input = {
userSub: id,
username: username,
userPhone: userPhone,
createdAt: createdAt,
}
await DataStore.save(new User(input)); // no { } around input here, to prevent it from getting nested You could then query by the user sub with the following: const user = await DataStore.query(User, c => c.userSub("eq", "3722f35e-de54-45b2-b26e-676e2cc48160")) |
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:
user profile loaded into DataStore is
once it is saved to the Datastore it looks like this.
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.
.
.
The text was updated successfully, but these errors were encountered: