Skip to content

API based on NestJS and GraphQL: filtering, sorting, paginating

Notifications You must be signed in to change notification settings

vresch/swiftcloud-api

Repository files navigation

SwiftCloud API

The #1 app for Taylor Swifties!

Description

Flexible API which exposes this data in different shapes and queries to enable an awesome frontend

Tech Stack

Typescript, NestJS, GraphQL, Prisma, SQLite, Docker

Installation

$ yarn install

Configuration

  1. Create a .env file in the root of the project
cp .env.example .env
  1. Migrate the database
yarn prisma migrate dev
  1. Seed the database (sqlite3 installed required)
yarn seed

Running the app

# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod

Docker

docker build -t swiftcloud-api .
docker run -t --name swiftcloud-api --env-file .env -p 3000:3000 swiftcloud-api

CI

The app is built and tested on every push to the main branch using GitHub Actions.

Deployment

GitHub Actions is used to deploy the app to Heroku. The app is deployed to https://swiftcloud-api-ad52e9ac6e6f.herokuapp.com/graphql

Playing around

In local dev try these queries in the GraphQL playground: http://localhost:3000/graphql

OR Copy and paste curl POST req below in your terminal:

curl -L -X POST "http://swiftcloud-api-ad52e9ac6e6f.herokuapp.com/graphql" \
-H "Content-Type: application/json" \
-d "{\"query\":\"query songList { \n  songList(\n    pagination: { first: 2 }\n    query: { year: 2020 }\n    orderBy: { field: \\\"playsJune\\\", direction: desc }\n  ) {\n    totalCount\n    pageInfo {\n      startCursor\n      hasNextPage\n      hasPreviousPage\n      endCursor\n    }\n    edges {\n      cursor\n      node {\n        id\n        song\n        year\n        playsJune\n      }\n    }\n  }\n}\",\"variables\":{}}"

Test

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

Next steps

  • Add more tests: unit, e2e, integration
  • Add more queries: search
  • Add more error handling
  • Add more logging: Sentry
  • Add more validation: Joi, class-validator
  • Add more security: disable grapql playground on prod, helmet, cors, rate limiting
  • Add more CI/CD: test coverage, code quality, code review
  • Add flexible deployment
  • Add more monitoring: New Relic, Datadog
  • Add more metrics: Prometheus
  • Add more caching: Redis
  • Add more performance optimizations: CDN, compression
  • Add more data relationships: plays by month
  • Add more data subscriptions: new songs

Stay in touch

About

API based on NestJS and GraphQL: filtering, sorting, paginating

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published