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.ts
extention in themodels/
directory that has the TypeORM@Entity
decorator 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, theCategory
entity is stored undercategoryModel
. -
All Repositories
An array of instances of each repository. Any file of
*.repository.ts
extention in therepositories/
directory is auto loaded and registered. Each repository is registered under its camel-case name. For example,CategoryRepository
is stored undercategoryRepository
. -
All Services
Services that extend the BaseService. Any file of
*.service.ts
extention in theservices/
directory is auto loaded and registered. Each service is registered under its camel-case name. For example, theCategoryService
is registered ascategoryService
. -
All Resolvers
Graphql resolvers exposing the graphql
Queries
,Mutations
and other schemas. Any file of*.resolver.ts
extention in theresolvers/
directory is auto loaded, registered and provided into theTypeGraphql
instance 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