GraphQL API for a blog platform built with NestJS, Apollo, and MongoDB.
This API powers the backend for a blog platform. It lets clients list posts, fetch a single post by slug, create new posts for authenticated users, and resolve author details for each post.
- GraphQL API with Apollo Server
- MongoDB integration through Mongoose
- Post queries with filter support
- Authenticated post creation
- User lookup and author resolution
- Environment-based configuration
- Containerized the backend application using Docker for consistent development and deployment environments
src/post- post resolver, service, schema, and GraphQL typessrc/user- user resolver, service, schema, and GraphQL typessrc/common- shared decorators, guards, and typessrc/main.ts- application bootstrap and CORS setup
Install dependencies:
npm installCreate a .env file with values similar to these:
PORT=3000
DATABASE_URL=mongodb://localhost:27017/blog-platform
CLIENT_URL=http://localhost:3000
NODE_ENV=developmentnpm run startDevelopment mode:
npm run start:devProduction mode:
npm run start:prodnpm run build- compile the TypeScript projectnpm run format- format source and test files with Prettiernpm run format:check- check formatting without changing filesnpm run lint- run ESLint with auto-fixnpm run lint:check- run ESLint without auto-fixnpm run check:both- run lint check and format checknpm run fix:both- run lint and format fixesnpm run test- run unit testsnpm run test:watch- run tests in watch modenpm run test:cov- run tests with coveragenpm run test:debug- run Jest in debug modenpm run test:e2e- run end-to-end tests
The app generates its schema from the code and writes it to src/schema.gql.
Key operations include:
getPosts- list posts with optional filtersgetPostBySlug- fetch a single post by slugcreatePost- create a post for the authenticated usergetUser- list users