A basic GraphQL API server using NodeJS, TypeScript, Yoga GQL, Prisma, and Pothos GraphQL to manage a simple list of tasks.
- Node.js
- TypeScript
- Yoga GQL
- Pothos GQL
- Prisma
- Zod
- Node.js
- pnpm or npm
- A Prisma Postgres database
git clone https://github.com/<github user>/simple-task-list-api.git
cd simple-task-list-api# pnpm (recommended)
pnpm install
# npm
npm installThis project uses a Prisma Postgres database. Run the following command to create a Prisma database:
# pnpm
pnpm dlx create-db
# npm
npx create-dbOnce provisioned, copy the database URL provided by the command.
Use the following command to create a local .env file. Then open the new file (.env) to make sure the DATABASE_URL value is replaced with the URL of your Prisma Postgres database.
cp .env.example .envDATABASE_URL="postgres://..."Run Prisma migrations to set up the database schema:
# pnpm
pnpm prisma migrate dev
# npm
npx prisma migrate devAfter running the prisma migrate command, the need tu run prisma generate to generate the Prisma client:
# pnpm
pnpm prisma generate
# npm
npx prisma generatepnpm dev # pnpm
npm run dev # npmThe GraphQL endpoint will be available at http://localhost:4000/graphql.
| Field |
|---|
id |
title |
completed |
createdAt |
updatedAt |
query {
tasks {
id
title
completed
}
}query {
task(id: "TASK_ID") {
id
title
completed
}
}mutation {
createTask(title: "Buy groceries") {
id
title
completed
}
}mutation {
updateTask(id: "TASK_ID", title: "Buy groceries", completed: true) {
id
title
completed
}
}mutation {
deleteTask(id: "TASK_ID") {
id
title
completed
}
}