Skip to content

Commit

Permalink
feat(cli): expose graphql endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
endersonmaia committed Dec 5, 2024
1 parent 45efe41 commit 55f8c26
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-penguins-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

expose graphql endpoint
11 changes: 11 additions & 0 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default class Run extends BaseCommand<typeof Run> {
"disable local paymaster service to save machine resources",
summary: "disable paymaster service",
}),
"disable-graphql": Flags.boolean({
default: false,
description:
"disable local graphql service to save machine resources",
summary: "disable graphql service",
}),
"epoch-length": Flags.integer({
description: "length of an epoch (in blocks)",
default: 720,
Expand Down Expand Up @@ -136,6 +142,11 @@ export default class Run extends BaseCommand<typeof Run> {
// proxy
composeFiles.push("docker-compose-proxy.yaml");

// graphql
if (!flags["disable-graphql"]) {
composeFiles.push("docker-compose-graphql.yaml");
}

// anvil
composeFiles.push("docker-compose-anvil.yaml");

Expand Down
51 changes: 51 additions & 0 deletions apps/cli/src/node/docker-compose-graphql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
graphql_database_creator:
image: postgres:15-alpine
command: ["createdb", "hlgraphql"]
depends_on:
database:
condition: service_healthy
environment:
PGHOST: ${PGHOST:-database}
PGPORT: ${PGPORT:-5432}
PGUSER: ${PGUSER:-postgres}
PGPASSWORD: ${PGPASSWORD:-password}
PGDATABASE: ${PGDATABASE:-postgres}

graphql:
image: cartesi/sdk:devel
environment:
POSTGRES_GRAPHQL_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/hlgraphql?sslmode=disable
POSTGRES_NODE_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/${PGDATABASE:-postgres}?sslmode=disable
expose:
- 8080
command: ["cartesi-rollups-hl-graphql", "--graphile-disable-sync"]
depends_on:
graphql_database_creator:
condition: service_completed_successfully

prompt:
image: debian:bookworm-slim
environment:
PROMPT_TXT_04_GRAPHQL: "graphql endpoint running at http://localhost:${CARTESI_LISTEN_PORT}/graphql/"

traefik-config-generator:
environment:
TRAEFIK_CONFIG_GRAPHQL: |
http:
routers:
graphql:
rule: "PathPrefix(`/graphql`)"
middlewares:
- "remove-graphql-prefix"
service: graphql
middlewares:
remove-graphql-prefix:
replacePathRegex:
regex: "^/graphql/(.*)"
replacement: "/$1"
services:
graphql:
loadBalancer:
servers:
- url: "http://graphql:8080"

0 comments on commit 55f8c26

Please sign in to comment.