All Projects → arbytez → boilerplate-nexus-prisma-apollo-graphql-express

arbytez / boilerplate-nexus-prisma-apollo-graphql-express

Licence: MIT license
Boilerplate project for a graphql server using nexus-prisma and apollo-server-express

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to boilerplate-nexus-prisma-apollo-graphql-express

nexus-validate
🔑 Add argument validation to your GraphQL Nexus API.
Stars: ✭ 29 (-6.45%)
Mutual labels:  nexus, prisma2
gql2sql
GraphQL to SQL service example
Stars: ✭ 31 (+0%)
Mutual labels:  apollo-server, prisma2
graphql-compose-elasticsearch
Graphql App using Node with typescript, KOA framework and Elasticsearch
Stars: ✭ 40 (+29.03%)
Mutual labels:  apollo-server
graphql-resolver-cache
Caching for Graphql Resolvers
Stars: ✭ 18 (-41.94%)
Mutual labels:  apollo-server
apollo-server-midway
Apllo-Server integration for Midway & Midway Serverless
Stars: ✭ 13 (-58.06%)
Mutual labels:  apollo-server
vacomall
☀️☀️ 基于 dubbo 实现的分布式电商平台。
Stars: ✭ 42 (+35.48%)
Mutual labels:  nexus
graphql-scalars
📐 A library of custom GraphQL scalar types for creating precise type-safe GraphQL schemas, with validation powered by Yup.
Stars: ✭ 68 (+119.35%)
Mutual labels:  apollo-server
apollobank
A full stack GraphQL banking application using React, Node & TypeScript.
Stars: ✭ 203 (+554.84%)
Mutual labels:  apollo-server
apollo-errors
Machine-readable custom errors for Apollostack's GraphQL server
Stars: ✭ 408 (+1216.13%)
Mutual labels:  apollo-server
perseus
An Apollo GraphQL Server & React Client in a Yarn Workspace deployed with Zeit 2.0
Stars: ✭ 35 (+12.9%)
Mutual labels:  apollo-server
create-graphql-app
Cli tool for bootstrapping serverless GraphQL api
Stars: ✭ 28 (-9.68%)
Mutual labels:  apollo-server
intellij-prisma
Prisma schema file support for IntelliJ IDEs (WebStorm, PHPStorm, Pycharm, RubyMine, ...)
Stars: ✭ 25 (-19.35%)
Mutual labels:  prisma2
n3dr
Nexus3 Disaster Recovery (N3DR) is a tool that is capable of downloading all artifacts from a Nexus3 server and to migrate them to another Nexus3 server. Note that some repository formats are not supported at the moment.
Stars: ✭ 110 (+254.84%)
Mutual labels:  nexus
netapp-cdot-nagios
Nagios-Checks for monitoring NetApp cDOT-Systems via NetApp Perl API
Stars: ✭ 40 (+29.03%)
Mutual labels:  nexus
wordops-dashboard
Dashboard for WordOps backend
Stars: ✭ 35 (+12.9%)
Mutual labels:  backend-server
schemaglue
Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
Stars: ✭ 117 (+277.42%)
Mutual labels:  apollo-server
apollo-express-ts-server-boilerplate
No description or website provided.
Stars: ✭ 29 (-6.45%)
Mutual labels:  apollo-server
apollo-directive
tools for easy (and finally readable!) directive implementation in Apollo Server or any server using graphql-tools.makeExecutableSchema
Stars: ✭ 13 (-58.06%)
Mutual labels:  apollo-server
blitz
⚡️The Fullstack React Framework — built on Next.js
Stars: ✭ 11,558 (+37183.87%)
Mutual labels:  prisma2
nodejs-graphql-template
Template project for Node.js® GraphQL APIs
Stars: ✭ 13 (-58.06%)
Mutual labels:  apollo-server

Boilerplate project for nexus-prisma apollo-express-graphql backend server

⚠️ Disclaimer: the project uses the prisma framework that is not ready for production yet. See isprisma2ready.com.

Code written using nodejs version LTS >= 12.x.x.

This project wants to be a starting point for more complex backend projects using graphql. Of his own, it manages the backend for a simple todo application but it handles important other topics besides the basic crud api for todos.

Getting started

The project uses nps (npm-package-scripts) so in the file package.json there are only 3 scripts, one for each main environment, and the scripts logic inside package-scripts.js:

"scripts": {
    "dev": "cross-env NODE_ENV=development nps",
    "prod": "cross-env NODE_ENV=production nps",
    "test": "cross-env NODE_ENV=test nps"
  },
npm i                                       # install dependencies packages (there are a few 😧)
npm run <dev|test|prod> generate            # generate prisma-client-js library and typescript definitions for nexus-prisma. Before doing it, set the environment variables needed
npm run dev                                 # start development server
npm run test                                # start jest tests suite
npm run prod                                # generate, build and start the production server

npm run <dev|test|prod> prisma.migrate         # create migration
npm run <dev|test|prod> prisma.migrate.up      # apply migration
npm run <dev|test|prod> prisma.migrate.down    # rollback migration

npm run dev generate.nexus                  # useful to generate only the nexus typescript definitions while implementing new features

Environment variables

Check file environment.example.env or test.example.env, then create for each environment the relative env file with the env var wanted.

config/development.env                      # for development
config/test.env                             # for test
config/production.env                       # for production
  • COOKIE_SECRET cookie secret for signed cookies
  • FRONTEND_URLS list of urls separated by a comma for cors options
  • JWT_SECRET jsonwebtoken secret for auth operations
  • JWT_TOKEN_EXPIRES_SEC_IN amount of seconds that the generated jwt token will be valid
  • PORT server port, default 4000
  • DATABASE_URL database (postgres) db access url
  • REDIS_HOST redis db hostname, used for graphql subscriptions
  • REDIS_PASSWORD redis db password
  • REDIS_PORT redis db port, default 6379
  • WRITE_CUSTOM_LOG_TO_FILE yes/no, write log only to console or console and filesystem

Graphql server security

Tests (Broken [todo])

> ⚠️ with the latest versions the property enabled on datasource section on schema.prisma is no longer available and since the test environment changes the db source dynamically for every test cases, for the moment, it is not possible to run the test suite. Although this feature is implemented (see here prisma/prisma#1487) the test suite is still broken because it uses the sqlite provider with an enum for the roles but sqlite does not support enum types. It is needed to switch the test db provider to postgres.

Before run npm run test, set the config/test.env file and run npm run test prisma.migrate.up (check prisma docs to see the correct flow to follow). This command will set your sqlite db on /src/tests/db/data.sqlite. This db should not contain data and schema must be updated (run prisma.migrate.up in test env every time the schema.prisma is updated).

Each test suite will do (see testUtils.ts):

  1. a copy of the data.sqlite into the /src/tests/db/generated folder
  2. start the backend server, the port is choosen using arbitrary-unused-port
  3. seed the copied db with 'dummy' data that test will use it.
  4. run tests
  5. clean test environment (close backend server, Prisma-Client connection and delete the copied sqlite db)

Todo

  • test graphql subscriptions
  • optimize tests flow (tests run need a lot of pc resources to bootstrap the server for each test suite and compilation from typescript)
  • upload file endpoint (not needed but nice to have into the boilerplate project)
  • process manager in production (npm run prod will start the api with pm2 in cluster mode)
  • use some kind of autogenerated documentation tool system and publish it to GET / of the backend server. Used https://github.com/2fd/graphdoc.

Other

The backend is ready to be used with CapRover, indeed captain-definition file exist on the root project (see also dockerfile).

One instance of the backend project is up and running on: https://nexus-prisma-boilerplate.epbe.dynu.net/graphql (auto-generated docs: https://nexus-prisma-boilerplate.epbe.dynu.net/). The FRONTEND_URLS env var is set to http://127.0.0.1:3000,http://localhost:3000 so it is possible to play with the backend with a local frontend environment (like nextjs).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].