Monsoon is a Gateway service as its schema is using a GraphQL design pattern called Schema Stitching. Stitching allows us to merge multiple remote services (both GraphQL and RESTful APIs) into a single endpoint.
You can explore the Monsoon API using the staging GraphQL Playground
- Install Docker command line tools. You can get them by visiting the Docker Website and downloading the desktop client.
# 1 Ensure you are using correct Node version
nvm install v16.4.0
# 2. Installs all required dependencies
yarn
# 3. Setup an environment variable file
cp .env.example .env
# 4. Get env vars from Heroku (assuming you have installed the Heroku cli and run heroku login)
heroku config -s -a monsoon-staging
# This will set you up to connect to the staging server. If you wish to use the local Docker container, modify
# the following env vars:
PRISMA_ENDPOINT=http://localhost:4466/monsoon/dev
DATABASE_URL='postgres://prisma:prisma@localhost:9876/prisma?schema=monsoon$dev'
REDIS_URL=redis://localhost:6379
# 5. Create your local Postgres and Redis instances
docker-compose up -d
# 6. Install monsoon-cli (command line interface)
yarn global add ts-node && yarn link
# 7A. Create a superuser on your database. Run this SQL against your local DB. (You can use Postico for this)
CREATE USER postgres SUPERUSER;
# 7B. Get a fresh copy of the database from production
monsoon spp local
# 9. Start server (runs on http://localhost:4000/playground) and open GraphQL Playground
yarn start
To verify the server is setup properly. go open the playground and run the following query
{
productsConnection(first: 10) {
edges {
node {
id
name
}
}
}
}
All deployments follow the following pattern.
- Create a Pull Request for your branch code onto
master
. - Once that PR is reviewed and merged to
master
, our code will automatically deploy to the staging server. - Once your code passes QA on staging, use Heroku's "Promotion" feature on this page to deploy to production.
Before deploying to production your first time, please check with a senior member of the engineering team.
Video walkthroughs are available here.
yarn start
starts GraphQL server onhttp://localhost:4000
Monsoon ships with a command line interface. To install it run yarn link
. Once that's complete, you can use the following commands:
monsoon sync:prisma:prisma
to sync the production db to staging/local, or the staging db to local.
For details on the arguments and options for each command, use --help
. e.g monsoon sync:prisma:prisma --help
Note that you may need to run yarn tsc
to generate the files used by the monsoon cli.
You can generate a random test user using the following command
monsoon ctu --password Seasons2020 --prisma local --roles Customer Admin
If you're working against the staging server, run the staging version:
monsoon ctu --password Seasons2020 --prisma staging --roles Customer Admin
If --email
and/or --password
are not specified, those values are auto generated. All random values are generated using a library called faker.js
Sometimes, you need to take over a user's account and use one of our applications as them in order to debug an issue. Refrain from doing this on production, as it requires the user later needing to update their password.
Instead, you can first sync their data from production to your local database, then takeover their account as follows:
monsoon sync:prisma:prisma local
monsoon takeover [email protected]
You can also do this on staging as follows:
monsoon sync:prisma:prisma staging
monsoon takeover [email protected] --pe staging
You should have .env
, .env.staging
, and .env.production
that declare the environment variables for your local, and the staging and production environments respectively.
You can copy the staging and production environment variables directly from heroku using the heroku command line tool:
heroku config -s --app monsoon-staging > .env.staging
heroku config -s --app monsoon-production > .env.production
.
You can set environment variables on heroku from your CLI with the following command:
- `heroku config:set {ENV_VAR_NAME}={ENV_VAR_VALUE} -a {HEROKU_APP_NAME}
For example, to see the variable HELLO with value WORLD on app monsoon-staging, you'd do:
heroku config:set HELLO=WORLD -a monsoon-staging
You may need to install the CLI and login using heroku login
first.
File name | Description |
---|---|
├── .env |
Defines environment variables |
├── .graphqlconfig.yml |
Configuration file based on graphql-config (e.g. used by GraphQL Playground). |
└── database (directory) |
Contains all files that are related to the Prisma database service |
├── prisma.yml |
The root configuration file for your Prisma database service (docs) |
└── datamodel.graphql |
Defines your data model (written in GraphQL SDL) |
└── src (directory) |
Contains the source files for your GraphQL server |
├── index.ts |
The entry point for your GraphQL server |
├── schema.graphql |
The application schema defining the API exposed to client applications |
├── resolvers (directory) |
Contains the implementation of the resolvers for the application schema |
└── generated (directory) |
Contains generated files |
└── prisma-client (directory) |
The generated Prisma client |
- When sending a push notification with a route to Harvest, the data must match Harvest's navigation convention.
E.g.
navigation.navigate("Modal", { screen: "FiltersModal", params: { sizeFilters } })
would appear as:
...
data: {
route: "Modal",
screen: "FiltersModal",
params: {
sizeFilters: ["Medium"],
},
},
...
In the event of a DEFCON 5 where we need to drop the current database and replace it with a replica, make sure to do the following afterwards in order to ensure complete the transition:
- Update the .pgpass and .env files in the
monsoon-scripts
folder on s3 - Update the DB connection in looker
- Update the warehouse settings on segment to load into the new DB.
- Update the warehouse settings on stitch (addresses chargebee, shippo, stripe)