I'm using AWS Amplify API (as I understand, this is AWS AppSync and Amplify DataStore) with TypeScript.
I've created a graphql type
type PrivateNote
@model
@auth(rules: [{ allow: owner, ownerField: "owner" }])
@key(fields: ["owner", "id"]) {
owner: String!
id: ID!
content: String!
}
Note the @auth which specifies ownerField: "owner" and the @key including owner.
The goal of that type is that only creators ("owner") can view/update/delete their data and that the generated DynamoDB's primary key is ["owner", "id"].
Using the type as noted above I can successfully generate the code using
# for backend code
amplify api gql-compile
# for frontend code
amplify codegen model --nodownload
The problem is that now I have to explicitly set the owner when creating instances of PrivateNote like
const n = new PrivateNote({
content: "my content",
owner: "the-owner-id"
});
If I don't set the owner, the TypeScript compiler complains and there is also a runtime error saying
Property 'owner' is missing in type ...
Before setting the @key in the graphql schema (and hence also omitting it in the field list of PrivateNote) I didn't have to set owner, it was done automatically behind the scenes.
So how can I add the owner to a @key and still have it auto-filled? And what needs to be changed to have the TypeScript typings generated accordingly?