A modern GraphQL API implementation that demonstrates best practices for building scalable and maintainable GraphQL services.
- GraphQL API using Apollo Server for efficient data fetching
- TypeScript for type safety and improved developer experience
- Prisma ORM for type-safe database access and migrations
- PostgreSQL for reliable data storage
- Modular Architecture with clear separation of concerns
- Development Tools for a streamlined development workflow
- Backend Framework: Apollo Server
- Language: TypeScript
- ORM: Prisma
- Database: PostgreSQL
- Package Manager: pnpm
- Development Tools: Nodemon, Prettier, dotenv
- Node.js (>= 16.x)
- pnpm (>= 10.7.0)
- PostgreSQL database
# Clone the repository
git clone https://github.com/Xjectro/graphql.git
cd graphql
# Install dependencies
pnpm install
Create a .env
file in the root directory with your database connection string:
DATABASE_URL="postgresql://username:password@localhost:5432/graphql"
# Create migrations based on your schema
pnpm db:migrate
# Generate Prisma client
pnpm db:generate
# Start the development server
pnpm dev
The GraphQL server will be running at http://localhost:4000
.
# Get all turtles
query {
turtles {
id
name
}
}
# Create a new turtle
mutation {
createTurtle(name: "Leonardo") {
id
name
}
}
├─ src/
│ ├─ graphql/ # GraphQL schemas and resolvers
│ │ ├─ resolvers/ # Query and mutation resolvers
│ │ ├─ schemas/ # GraphQL type definitions
│ ├─ models/ # Database client setup
│ ├─ services/ # Business logic layer
│ └─ index.ts # Server entry point
├─ prisma/ # Prisma schema and migrations
└─ ...config files
pnpm dev
- Start development server with hot reloadpnpm format
- Format code with Prettierpnpm db:migrate
- Create new database migrationspnpm db:generate
- Generate Prisma clientpnpm db:reset
- Reset the databasepnpm db:status
- Check migration statuspnpm db:push
- Push schema changes to database
This project is licensed under the ISC License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Project Link: https://github.com/Xjectro/graphql