Skip to content

ramzitannous/medium-graphql-nestjs

Repository files navigation

[Nestjs + Mongodb + Graphql]

enter image description here

[Nestjs + Graphql] codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the 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 (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 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

Graphql Upload

graphql file upload was done by graphql-upload node package

Graphql Schema

full graphql schema can be found at 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.