Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): expose graphql endpoint #134

Open
wants to merge 2 commits into
base: feature/add-hl-graphql-to-sdk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
// 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 Expand Up @@ -208,7 +219,7 @@
});
} catch (e: unknown) {
// 130 is a graceful shutdown, so we can swallow it
if ((e as any).exitCode !== 130) {

Check warning on line 222 in apps/cli/src/commands/run.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 222 in apps/cli/src/commands/run.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
throw e;
}
} finally {
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", "graphql"]
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}/graphql?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"
Loading