https://github.com/ramzitannous/medium-graphql-nestjs
A medium like graphql server using nestjs + graphql
https://github.com/ramzitannous/medium-graphql-nestjs
codebase crud dataloader graphql graphql-schema mongodb nestjs-graphql nodejs pagination subscription
Last synced: about 2 months ago
JSON representation
A medium like graphql server using nestjs + graphql
- Host: GitHub
- URL: https://github.com/ramzitannous/medium-graphql-nestjs
- Owner: ramzitannous
- Created: 2021-05-29T17:37:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-18T21:37:14.000Z (about 4 years ago)
- Last Synced: 2025-02-01T07:31:38.961Z (11 months ago)
- Topics: codebase, crud, dataloader, graphql, graphql-schema, mongodb, nestjs-graphql, nodejs, pagination, subscription
- Language: TypeScript
- Homepage:
- Size: 738 KB
- Stars: 56
- Watchers: 2
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [Nestjs + Mongodb + Graphql]

> ### [Nestjs + Graphql] codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the [RealWorld](https://github.com/gothinkster/realworld) spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with **Nestjs + Graphql** including CRUD operations, authentication, routing, pagination, and more.
# Screenshots
**create user**
**JWT login**
**add article to favorite**
**create article**
**get all articles and comments with pagination**
**add comment to article**
# How it works
A medium like backend server using nestjs with Graphql and mongodb as presitance layer.
**Packages**
1. `@nestjs/config`: Configuration module with .env support for nestjs
2. `@nestjs/jwt`: Support JWT authentication for nestjs
3. `@nestjs/mongoose`: support [mongoose](https://mongoosejs.com/) (Mongodb ORM) for nestjs
4. `@nestjs/passport`: Nodejs authentication module that supports multiple strategies
5. `@nestjs/graphql`: Add Graphql support for nestjs
6. `graphql-subscriptions`; Add subscription with websockets for graphql
7. `dataloader`: support graphql batch loading
8. `graphql-upload`: add file upload to graphql
**Why Dataloader ?**
[Dataloader](https://github.com/graphql/dataloader) is used to solve the popular **N+1** problem, by batching requests and making one rquest to the database to fetch multiple objects, instead of **N** queries, this will optimize the graphql queries significantly, more about the problem can be found [here](https://medium.com/the-marcy-lab-school/what-is-the-n-1-problem-in-graphql-dd4921cb3c1a)
**Graphql Upload**
graphql file upload was done by `graphql-upload` node package
**Graphql Schema**
full graphql schema can be found at [schema.gql](https://github.com/ramzitannous/medium-graphql-nestjs/blob/master/src/schema.gql)
**Graphql Subscription**
subscription is done using `graphql-subscriptions`, 2 events can be subscribed:
**1. when article created**
**2. when a new comment added**
# Getting started
1. add `.env` file with fallowing values:
`SERVER_PORT=3000`
`MONGODB_URI=mongodb://localhost:27017/medium`
`DEBUG=true`
`SECRET_KEY=secret-key`
`UPLOAD_PATH=./static`
2. `yarn install`
3. `yarn start`
4. Head to `http://localhost:3000/graphql` to check graphql playground.