Skip to content

osalama7/nest-gql-sample

Repository files navigation

NestJS GraphQL Sample

A starter repository for building efficient, scalable server-side applications with NestJS, GraphQL, and Prisma.


Project Setup

npm install

Development

Start the development server:

npm run start:dev

Production Build

npm run build
npm run start:prod

Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

Database & Prisma

1. Start PostgreSQL with Docker

docker-compose up -d

2. Configure Database

Edit .env if needed. Default:

DATABASE_URL="postgresql://nestuser:nestpass@localhost:5432/nestgql?schema=public"

3. Run Prisma Migrations

npm exec prisma migrate deploy

4. Generate Prisma Client

npm exec prisma generate

5. Run Database seeds

npx prisma db seed 

GraphQL Code Generation

This project uses GraphQL Code Generator to generate TypeScript types and resolvers from your GraphQL schema.

1. Update the GraphQL Schema

Edit schema.graphql as needed.

2. Generate Types

npm run codegen

This will generate types in src/generated/graphql.ts.


Using Prisma Client

You can use the generated Prisma Client in your services. Example:

import { PrismaService } from '../prisma.service';

@Injectable()
export class ExampleService {
  constructor(private prisma: PrismaService) {}

  async getAuthors() {
    return this.prisma.author.findMany();
  }
}

Useful Commands

  • Format code:
    npm run format
  • Lint code:
    npm run lint

Resources


License

UNLICENSED

About

basic nest gql starter with Prisma and postgres

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published