2.1.4 • Published 4 years ago

walter-backend v2.1.4

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 years ago

General

This is the main repo for the backend of Walter.

Features

In this project the Nexus framework is the GraphQL API, Prisma is an programming API to use in our code to interact with the database.

For a fully-fledged GraphQL & Node.js tutorial, visit How to GraphQL

Software requirements

  1. You need NodeJS installed (version >= 14). Suggestion use the n-install script to manage Node versions.
  2. You need Yarn classic 1.x installed. See your OS install steps here
  3. You need Docker installed. See your OS install steps here
  4. You need Docker compose installed. See your OS install steps here

Getting started

Setup

Our application requires 2 .env files. One that Prisma is looking for under ./prisma and another for configuring everything else.

  1. Create the ./prisma/.env file and in it put DATABASE_URL=postgresql://postgres:k0fpEoFJetxkObPD@localhost:5432/walter. This login credential is the one you can find in docker-compose.yml
  2. Ask a coworker for environment variables to fill in .env file at the root of the project. It needs it to know where to connect to Redis and configure different third parties.
  3. Download the file from https://drive.google.com/file/d/1OXMIht11Yngxew8WoeeOY6ZVxj9ffxaF/view?usp=sharing saved under the name staging-walter-backend-storage.json to be at the root of the project and add the following to your .env file. This is used for file upload from your machine to staging for some API calls.
PROJECT_ID=staging-288420
KEY_FILENAME=staging-walter-backend-storage.json
FILES_BUCKET_NAME=walter-staging

Starting up

# Start the required database (the -d option is to run it in daemon mode, in the background)
docker-compose up -d

# 1. Install depedencies
yarn install

# 2. Generate prisma code based on schema (datamodel.prisma).
yarn prisma generate

# 3. Create the database structure without data
yarn db:up

# 4. Add some seed data. Once the script is done, in the output of the console, take note of your manager and resident user names and of the manager user password once the script is done and of the instructions on where to use the provided credentials. To generate a manager user with a managing company, you can also start the manager-web frontend, go to http://localhost:3000/auth/register, then register a company and take note of your user email in the user profile (the password will be 12345678 by default).
yarn seed

# 5. Start dev server
yarn dev

Commands

  • yarn dev starts GraphQL server on http://localhost:5000
  • yarn worker-dev Run worker jobs locally
  • yarn build Build the code for production. It creates a .nexus folder with JS code and it's own node_modules.
  • yarn test:unit runs the unit tests only
  • yarn test:int runs the integration tests and needs the Postgres database to be accessible locally to work
  • yarn test do both the above

Project structure

File nameDescription
├── .envDefines environment variables
├── .graphqlconfig.ymlConfiguration file based on graphql-config (e.g. used by GraphQL Playground).
└── prisma (directory)Contains all files that are related to the Prisma database service\
├── prisma/.envPrisma looks for this file for environment variables
└── prisma/schema.prismaDefines your data model (written in GraphQL SDL)
└── api (directory)Contains the source files for your GraphQL server
├── api/app.tsThe entry point for your GraphQL server
├── schema.graphqlThe application schema defining the API exposed to client applications
├── api/resolvers (directory)Contains the implementation of the resolvers for the application schema
└── api/generated (directory)Contains generated files
└── prisma.grapghqlThe Prisma database schema defining the Prisma GraphQL API

Documentation

For further documention please look this project Wiki or the wiki tab above.