This is the nexus of the project where the state of the app is stored. This contains two important components:
Prisma is open-source ORM. In this project. It's uses postgres
as data source; Prisma manage and create the govrn
Database cluster for you. In addtion, Prisma has a performant query engine that is implemented in Rust.
You can find all configuration under the schema.prisma
file. Schema Docs
Prisma makes it easier for 2 main jobs:
- generate: provides a TypeGraphQL integration with Prisma. Currently, it uses
typegraphql-prisma
- migrating Database after changes are made to the prisma schema.
This Diagram shows the general relationships among all tables in postgres DB.
Express creates a GraphQL server with many useful middlewares that manage session & permissions. Most other applications in Govrn monorepo is dependent on it. In many application, you are going to need PROTOCOL_URL
for GraphQL:
PROTOCOL_URL="http://localhost:4000/graphql"
You can find more about the configurations and middleware under main.ts
file.
Install postgresql@13
on your OS. It's required by Prisma to operate.
Here's a gist for macOS.
-
Install
postgresql@13
binaries. -
Define a new PostgreSQL user account using
createuser
:createuser --interactive --pwprompt
-
To integrate
postgresql
into the project, you need theDATABASE_URL
that references the Database Cluster on your OS.DATABASE_URL=postgresql://<username>:<password>@localhost:5432/govrn
-
Finally, run
yarn nx run protocol-api:migrate
. This will create PostgreSQL database cluster calledgovrn
Your database is now in sync with prisma schema @apps/protocol-api/prisma/schema.prisma
. -
You can access the
govrn
database cluster usingpsql govrn
or using pgcli for auto-completion.
This App is generated using @nrwl/node:application
. Check all targets at project.json
yarn nx run protocol-api:serve
: start a GraphQL server athttp://localhost:4000/graphql
.yarn nx run protocol-api:generate
: runsprisma generate
command, generating artifacts (e.g.PrismaClient
).1yarn nx run protocol-api:migrate
: runsprisma migrate
command, migrating and creating the database if it does not exist.1yarn nx run contract-sync-job:lint
PROTOCOL_COOKIE_SECRET
: secret A string which will be used as single key. You can use any string, ex:PROTOCOL_COOKIE_SECRET="truculent Falafel"
CORS_ORIGIN
: A comma separated list of allowed origins. Locally it would belocalhost:3000
.KEVIN_MALONE_TOKEN
: Authorization token for GraphQL requests.2LINEAR_REDIRECT_URI
: The redirect URI used by the frontend when authenticating a user via oAuth. It should look similar to http://localhost:4000/linear/oauthLINEAR_CLIENT_ID
: The client id of our linear appLINEAR_CLIENT_SECRET
: The client secret of our linear appDISCORD_REDIRECT_URI
: e.g. http://localhost:4000/discord/oauth for local development.DISCORD_CLIENT_ID
: The client ID of Discord app (Docs)DISCORD_CLIENT_SECRET
: Can be generated by creating an app on the Discord app docs (Docs)PROTOCOL_FRONTEND
: The url for our protocol frontend. It should look similar to http://localhost:3000LINEAR_JOB_TOKEN
: Authorization for GraphQL requests for linear sync job
Footnotes
-
uses
@nx-tools/nx-prisma
builder that provides a wrapper around the Prisma CLI. ↩ ↩2 -
As example it used at contract-sync-job app, check
CONTRACT_SYNC_TOKEN
env ↩