I am using AWS Amplify Datastore in Expo / React Native to store profile information using GraphQL.
schema looks like this:
type User @model {
id: ID!
username: String
userPhone: String
createdAt: String
updatedAt: String
}
Saving it to the datastore...
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",
},
}
The code examples show how to retrieve this record by datastore id
DataStore.query(User, c => c.id("eq", "f86d3252-7b1d-44f6-b4cd-b8a7a3a88def"));
However i want to retrieve it by the User id ("id": "3722f35e-de54-45b2-b26e-676e2cc48160") because the user id is actually the value of the CognitoUser sub which is readily available. Querying by datastore id would require saving the datastore id in AsyncStorage, state, context, redux or whatever which is more clunky.
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"));
I am sure there is a simple answer but i have been googling for days and cannot figure it out.
Thank you for your help.