A basic todo app to kickstart your NextJS 14 (App Router) and Go app, leveraging the ent framework for the data model and relay for data dependencies. It is designed to work out the box with Vercel hosting and serverless functions (providing your configuration, see below), but there is also a playground package you could deploy and run independently if you wanted instead.
- Clone the repo
- Ensure the Vercel CLI is installed
- Create a
.env.local
file with the following environment variables:
NEXT_PUBLIC_GRAPHQL_ENDPOINT="http://localhost:3000/api/graphql"
DATABASE_URL=<your_dev_database_url>
NOTE: If using a database other than MySQL you will need to add the corresponding database driver and update the calls to
ent.Open
- Set the
DATABASE_URL
environment variable and rungo run go/cmd/db/migrate.go
to create/update the database tables
NOTE: I recommend using the dotenv CLI to load the environment variables from the
.env.local
in the previous step:dotenv -e .env.local go run go/cmd/db/migrate.go
- Run
vercel dev
Relay depends on a schema file being generated by ent. If you make any changes to your data model, run the app with vercel dev
then you can run npm run schema
to update the schema with the latest changes from ent.
For production you probably want to use versioned migrations. See the docs at https://entgo.io/docs/versioned-migrations.
If you want a simple automatic migration for your dev db, then you can run the go/cmd/db/migrate.go
package.
NOTE: My migration has foreign keys disabled because I was using Planetscale to host the DB which does not support foreign keys. Unless using Planetscale, you will want to remove this.