An open API service indexing awesome lists of open source software.

https://github.com/qiweiii/anp-stack

Apollo Server + Nexus + Prisma4 Backend Service Boilerplate
https://github.com/qiweiii/anp-stack

apollo-server boilerplate graphql graphql-nexus kubernetes prisma prisma4 template template-repository

Last synced: 7 months ago
JSON representation

Apollo Server + Nexus + Prisma4 Backend Service Boilerplate

Awesome Lists containing this project

README

          

## Intro

A template for boostrapping a backend service(GraphQL & Restful) using *Apollo Server + Nexus + Prisma* stack, with various other useful tools like devops, testing, etc.

## Stack

- **Apollo Server v4 (with *Koa* integration)**: Run GraphQL & Http server
- **Nexus**: Writing code-first GraphQL schema
- **Prisma v4**: ORM
- **Postgres**: Relational Database
- **jest**: Unit tests
- **Github Action**: CI
- **Helm**: CD

## Getting Started

```
πŸ“¦ Sample App
┣ πŸ“‚ .github # Pipeline definition code.
┃ ┣ πŸ“‚ .github/workflows/cd.yml # GitHub action workflow.
┃ ┣ πŸ“‚ .github/deploy.yml # Deliverybot configuration file.
┣ πŸ“‚ infra # docker files and helm charts that manage our infrastructure.
┃ ┣ πŸ“‚ config # Contains value files per environment.
┣ πŸ“‚ prisma # Prisma schema.
┣ πŸ“‚ scripts # Some bash scripts need be to executed through pipeline。
┣ πŸ“‚ src
┃ ┣ πŸ“‚ common # Common stuff like constants, helpers functions。
┃ ┣ πŸ“‚ graqhpl # Graphql schema, types, resolvers。
┃ ┣ πŸ“‚ middleware # Koa middlewares.
┃ ┣ πŸ“‚ restful # Restful Koa route.
┃ ┣ πŸ“‚ setupServer # Setup koa + apollo server.
┃ ┣ πŸ“‚ types # TypeScript type definitions.
┃ ┣ πŸ“‚ utils
┃ ┣ πŸ“‚ app # service entrypoint.
┃ ┣ πŸ“‚ db # The PrismaClient after applying prisma middlewares.
┃ β”— πŸ“‚ logger # Logger for recording information/debug.
┣ πŸ“‚ tests # Jest tests.
β”— πŸ“œ package.json
```

- Start postgres database
- Create a new db named `anp-sample`
- OR you could run db via docker-compose
- `docker-compose -f infra/docker-compose/dev.yml up -d`
- `cp sample.env .env`, copy the `sample.env` into `.env` file
- `yarn`, install dependencies
- `yarn db:new-migration init`, migrate db & seed data (only the first time)
- `yarn dev`, run service, go to http://localhost:4000/graphql
- `yarn studio`, this is optional, then go to http://localhost:5555 and explore data.
- `yarn test`, run all `jest` unit test.
- Explore `package.json -> scripts` for more commands.

## Deploy to environments

## References
- [The Problems of "Schema-First" GraphQL Server Development](https://www.prisma.io/blog/the-problems-of-schema-first-graphql-development-x1mn4cb0tyl3)
- [Introducing GraphQL Nexus: Code-First GraphQL Server Development](https://www.prisma.io/blog/introducing-graphql-nexus-code-first-graphql-server-development-ll6s1yy5cxl5)
- [Prisma example: graphql-nexus](https://github.com/prisma/prisma-examples/blob/latest/typescript/graphql-nexus)
- [Similar tempalte: prisma-nexus-apollo-boilerplate](https://github.com/prisma-korea/prisma-nexus-apollo-boilerplate)
- [Helm Action](https://github.com/deliverybot/example-helm)

## Helpful debug issues

- [ambiguous NEXUS__UNKNOWN__TYPE error](https://github.com/graphql-nexus/nexus/issues/1119)
- [(DB Migration) Moving backwards and reverting all changes](https://www.prisma.io/docs/guides/database/production-troubleshooting#moving-backwards-and-reverting-all-changes)