Skip to content

Commit

Permalink
readme, env and devnet commands updated
Browse files Browse the repository at this point in the history
  • Loading branch information
MRVDH committed Sep 4, 2023
1 parent 9d14b26 commit 982545b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 46 deletions.
14 changes: 5 additions & 9 deletions packages/apps/graph/.env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

CHAIN_COUNT=20

# DEVNET
DATABASE_URL="postgresql://devnet@localhost:5432/devnet"

# Embedded postgres, you'll need to set the DATABASE_URL to the same value as EMBEDDED_DATABASE_URL
USE_EMBEDDED_POSTGRES=true
EMBEDDED_DATABASE_URL="postgresql://graphuser:graphpassword@localhost:55432/chainweb-data"
# EMBEDDED
USE_EMBEDDED_POSTGRES=false
#DATABASE_URL="postgresql://graphuser:graphpassword@localhost:55432/chainweb-data"
59 changes: 23 additions & 36 deletions packages/apps/graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @kadena/graph

GraphQL project, available for running your own GraphQL endpoint. This project
uses chainweb-data as datasource
uses chainweb-data as the datasource.

<picture>
<source srcset="https://raw.githubusercontent.com/kadena-community/kadena.js/main/common/images/Kadena.JS_logo-white.png" media="(prefers-color-scheme: dark)"/>
Expand All @@ -21,8 +21,8 @@ A GraphQL endpoint that interacts with chainweb-data.
First, install dependencies and build up to and including @kadena/graph

```sh
rush install -t @kadena/graph
rush build -t @kadena/graph
pnpm install --filter @kadena/graph
pnpm build --filter @kadena/graph
```

> **NOTE** you need Docker (or an alternative, e.g.
Expand All @@ -31,30 +31,30 @@ rush build -t @kadena/graph
You can run this project without running the devnet (that includes
chainweb-data) by using the embedded postgres server.

1. copy the `.env.example` to `.env`
1. copy the `.env.example` to `.env`

```sh
cp .env.example .env
```

2. choose between **embedded postgres** or **devnet**
2. choose between **embedded postgres** or **devnet**

1. **embedded postgres**: if you don't want to setup devnet, stop here.
2. **devnet**: if you want to use devnet, with chainweb-node, -miner and
-data change `.env`
1. **embedded postgres**: If you want to use the embedded database then set `USE_EMBEDDED_POSTGRES` to true and uncomment the `DATABASE_URL` from the embedded database section in the `.env` file. Skip step 3.
2. **devnet**: if you want to use devnet, with chainweb-node, -miner and
-data then set `USE_EMBEDDED_POSTGRES` to false in the `.env` file.

```sh
USE_EMBEDDED_POSTGRES=false
```
3. Start devnet:
3. In case you choose to run with devnet, start devnet:

```sh
docker run -it -p 8080:8080 -p 5432:5432 -p 9999:9999 -v $HOME/.devnet/l1:/root/.devenv enof/devnet:l2-latest-arm64
pnpm run devnet
```

In case you want to get the latest image, you can force docker to pull the
image: add `--pull always` after `docker run`
This command will start the existing image, and if not found, download and run a new image.

You can run `pnpm run devnet:update` to update the devnet image.

In case you always want to get the latest image, you can force docker to pull the
image by adding `--pull always` after `docker run` in the `devnet` script.

If something goes wrong, you can delete the mounted directory, and try to
start again:
Expand All @@ -64,32 +64,17 @@ chainweb-data) by using the embedded postgres server.
```

> **Windows alternative**
> replace `$HOME` with `%HomeDrive%%HomePath%`
> if you get an error try not mounting the volume by removing the part
> Replace `$HOME` with `%HomeDrive%%HomePath%` in the `devnet` script.
> If you get an error try not mounting the volume by removing the following part:
> `-v <arg>`

4. Execute custom migrations
Wait for the processes to start and "chainweb-node" and "postgres" to be
"Ready"
4. Start the project

```sh
rushx migrate-database
```
5. Add env var to `.env` and modify "USE_EMBEDDED_POSTGRES"
```
DATABASE_URL="postgresql://devnet@localhost:5432/devnet"
USE_EMBEDDED_POSTGRES=false
```
6. Start the project
```
rushx start
pnpm run start
```

7. Go to localhost:4000/graphql and execute this query to see if everything
5. Go to localhost:4000/graphql and execute this query to see if everything
works

```gql
Expand All @@ -106,6 +91,8 @@ chainweb-data) by using the embedded postgres server.

### Connect to the database

You can use Prisma's built in Studio as a database GUI, using `pnpm run prisma:studio`, or you can connect to the database using `psql`.
You need to have `psql` installed
([How to Install psql on Mac, Ubuntu, Debian, Windows](https://www.timescale.com/blog/how-to-install-psql-on-mac-ubuntu-debian-windows/))
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"main": "index.js",
"scripts": {
"build": "pnpm prisma:generate && heft build --clean",
"devnet": "docker run -it -p 8080:8080 -p 5432:5432 -p 9999:9999 -v $HOME/.kda-devnet/data:/data -v ./cwd-extra-migrations:/cwd-extra-migrations enof/devnet:l2-latest-arm64",
"devnet": "(docker start -ai devnet && docker exec -it devnet /bin/bash) || docker run -it -p 8080:8080 -p 5432:5432 -p 9999:9999 -v $HOME/.kda-devnet/data:/data -v ./cwd-extra-migrations:/cwd-extra-migrations --name devnet enof/devnet:l2-latest",
"devnet:update": "docker pull enof/devnet:l2-latest",
"format": "pnpm run /^format:.*/",
"format:src": "prettier config src --write",
Expand Down

0 comments on commit 982545b

Please sign in to comment.