I am basically trying to find an simple example of a Gen 2 function that creates a record in the amplify database. So basically a combination of this:
(from https://docs.amplify.aws/react/build-a-backend/functions/set-up-function/)
`import type { Schema } from "../../data/resource"
export const handler: Schema["sayHello"]["functionHandler"] = async (event) => {
// arguments typed from .arguments()
const { name } = event.arguments
// return typed from .returns()
return Hello, ${name}!
}
`
and this: (from https://docs.amplify.aws/react/build-a-backend/data/mutate-data/)
`import { generateClient } from 'aws-amplify/data';
import { type Schema } from '../amplify/data/resource'
const client = generateClient<Schema>();
const { errors, data: newTodo } = await client.models.Todo.create({
content: "My new todo",
isDone: true,
})`
This seems like a very common use case (I need it because I need to add a trusted timestamp from the server). There is a page that seems to slightly touch on this (https://docs.amplify.aws/react/build-a-backend/data/customize-authz/grant-lambda-function-access-to-api/) but the file layout is very different from the layout described in the functions section of the doc (https://docs.amplify.aws/react/build-a-backend/functions/) so I am wondering if it is out of date or referring to gen 1 (it looks like from the server I have to access it through the GraphQL API?).
I think a clear simple example of server side data access would be very useful for the docs.
Thanks!