A somewhat fully featured start template Express server application using Graphql and TypeORM.
-
A couple of security features have been implemented to help with DDoS, CSRF etc. This implementation should be regarded as starting points and should be built on. A list of integegrations
- Express Helmet - secure Express apps by setting HTTP response headers.
- Graphql Query Complexity Analysis - to help monitor/calculate/set the max query complexity/depth
- Rate Limiter - to help handle Throttling based on Query Complexity. See graphql security guide
-
Since this is built around TypeORM, class-validator was adopted to handle graphql argument and input validations. This builds on top of the regular apollo graphql field validation.
-
Awilix is used to implement and manage dependcy injection accross the app. A dependency container (AppContainer) is created to register essential resources which can then be accessed in classes and endpoints using the dependency container. Loaders are used to initialize the database connection, load plugins, register resources in the dependency container, and more.
The loaded and registed resources in the container are
-
All Entity Models
An array of all database entities that is passed to Typeorm when connecting to the database. Any file of
*.model.tsextention in themodels/directory that has the TypeORM@Entitydecorator will be automatically loaded, registered and added to the enitity manager. Each entity is registered under its camel-case name followed by Model. For example, theCategoryentity is stored undercategoryModel. -
All Repositories
An array of instances of each repository. Any file of
*.repository.tsextention in therepositories/directory is auto loaded and registered. Each repository is registered under its camel-case name. For example,CategoryRepositoryis stored undercategoryRepository. -
All Services
Services that extend the BaseService. Any file of
*.service.tsextention in theservices/directory is auto loaded and registered. Each service is registered under its camel-case name. For example, theCategoryServiceis registered ascategoryService. -
All Resolvers
Graphql resolvers exposing the graphql
Queries,Mutationsand other schemas. Any file of*.resolver.tsextention in theresolvers/directory is auto loaded, registered and provided into theTypeGraphqlinstance which in turns build the schema and provides it to the Apollo server.
-
- Node.js 14
- PostgresQL
- Typescript
- TypeORM
- Type Graphql
- Apollo Server + Express
To install dependencies, using then yarn pkg manager
$ yarn install# Generate migrations
$ yarn db:generate-migrations <NAME-OF-MIGRATION> --env=development
# Run migrations
$ yarn db:run-migrations --env=development$ yarn start:dev