Skip to content

martinstepanek/graphql-api-template

Repository files navigation

Serve API

  • Create ormconfig.json based on ormconfig.json.env and src/config.ts on src/config.ts.env
$ docker-compose exec api npm i
$ docker-compose up

URIs

Commands

  • npm run serve - Run GraphQL API
  • npm run migration - Handy shortcut for migration cmd (see https://typeorm.io/#/migrations)
  • npm run lint - Run eslint fix on ./src

Configurations

  • ormconfig.json - Database
  • nodemon.json - For nodemon plugin for development
  • docker-compose.yml - Docker services
  • tsconfig.json - TypeScript compilation
  • .eslintrc - For eslint

Directories in ./src

  • bootstrap - Contains functions for API bootstraping
  • migrations - Contains all (non-)generated migrations
  • resolvers - Contains GraphQl resolvers
  • models - Contains GraphQL/Entity models, Repositories, Services and Input models, Args models - grouped by type

Script types

  • <Type>Resolver - Resolver (GraphQL resolver can be compared with REST API controller)
  • <Type>Service - Service that provides data of <Type>
  • <Type>Input - Input data model, model that comes into resolver
  • <Type>Args - Argument model, defines arguments in queries for <Type>
  • <Type> - GraphQL model (model that goes out from API) and Entity database model at once

Important Libraries

  • Apollo Server - GraphQL server
  • TypeGraphQL - Layer for generation GraphQL schema from TypeScript
  • Type ORM - Database layer (supports MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, MSSQL, Oracle and MongoDB)
  • DataLoader - Batching/Caching data layer
  • Class Validator - Provides decorators for validating class properties
  • Apollo Metrics - Plugin to export basic GraphQL metrics
  • TS Node - TypeScript executor for Node
  • EsLint - Checking/Fixing code quality/standard tool

Testing

Mocha or https://github.com/alsatian-test/alsatian

TODO

  • Add unit tests

About

Template for fast setup developer friendly GraphQL server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •