I'd like to autofill a "userId" field when an object of this type is created.
type FriendRequest @model
@key(fields: ["userId", "receiver"])
{
userId: ID!
receiver: ID!
}
How would this be done? Would I need an @function directive on the userId field? What would that function look like?
Found the answer. Find the velocity resolvers in amplify\backend\api<your api name>\build\resolvers and move the mutations you want to edit into amplify\backend\api<your api name>\resolvers.
To autofill a field I used this line, which is based off the line of code used to autofill the "createdAt" and "updatedAt" fields for appsync api objects:
In my case I used $context.identity.sub to get the user's id, which I learned from this doc.