Skip to content

Commit 635e44e

Browse files
committed
feat(cli): expose graphql endpoint
1 parent 7feeb21 commit 635e44e

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

.changeset/heavy-penguins-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/cli": major
3+
---
4+
5+
expose graphql endpoint

apps/cli/src/commands/run.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export const registerRunCommand = (program: Command) => {
4040
false,
4141
)
4242
.option("--enable-espresso", "enable espresso development node", false)
43+
.option(
44+
"--disable-graphql",
45+
"disable local graphql service to save machine resources",
46+
false,
47+
)
4348
.option(
4449
"--no-backend",
4550
"run a node without the application code",
@@ -166,6 +171,11 @@ export const registerRunCommand = (program: Command) => {
166171
composeFiles.push("docker-compose-espresso.yaml");
167172
}
168173

174+
// graphql
175+
if (!disableExplorer) {
176+
composeFiles.push("docker-compose-graphql.yaml");
177+
}
178+
169179
// load the no-backend compose file
170180
if (backend) {
171181
composeFiles.push("docker-compose-host.yaml");
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
services:
2+
graphql_database_creator:
3+
image: postgres:16-alpine
4+
command: ["createdb", "graphql"]
5+
depends_on:
6+
database:
7+
condition: service_healthy
8+
environment:
9+
PGHOST: ${PGHOST:-database}
10+
PGPORT: ${PGPORT:-5432}
11+
PGUSER: ${PGUSER:-postgres}
12+
PGPASSWORD: ${PGPASSWORD:-password}
13+
PGDATABASE: ${PGDATABASE:-postgres}
14+
15+
graphql_database_migration:
16+
image: cartesi/sdk:0.12.0-alpha.8
17+
environment:
18+
POSTGRES_GRAPHQL_DB_URL: &graphql_db_url postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/graphql?sslmode=disable
19+
command:
20+
- /bin/bash
21+
- -c
22+
- |
23+
migrate \
24+
-source file:///usr/share/cartesi/rollups-graphql/migrations \
25+
-database $$POSTGRES_GRAPHQL_DB_URL \
26+
up
27+
depends_on:
28+
graphql_database_creator:
29+
condition: service_completed_successfully
30+
31+
graphql:
32+
image: cartesi/sdk:0.12.0-alpha.8
33+
environment:
34+
POSTGRES_GRAPHQL_DB_URL: *graphql_db_url
35+
POSTGRES_NODE_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/${PGDATABASE:-postgres}?sslmode=disable
36+
expose:
37+
- 8080
38+
command: ["cartesi-rollups-graphql"]
39+
depends_on:
40+
graphql_database_migration:
41+
condition: service_completed_successfully
42+
43+
prompt:
44+
image: debian:bookworm-slim
45+
environment:
46+
PROMPT_TXT_04_GRAPHQL: "GraphQL endpoint running at http://localhost:${CARTESI_LISTEN_PORT}/graphql/"
47+
48+
traefik-config-generator:
49+
environment:
50+
TRAEFIK_CONFIG_GRAPHQL: |
51+
http:
52+
routers:
53+
graphql:
54+
rule: "PathPrefix(`/graphql`)"
55+
middlewares:
56+
- "remove-graphql-prefix"
57+
service: graphql
58+
middlewares:
59+
remove-graphql-prefix:
60+
replacePathRegex:
61+
regex: "^/graphql/(.*)"
62+
replacement: "/$1"
63+
services:
64+
graphql:
65+
loadBalancer:
66+
servers:
67+
- url: "http://graphql:8080"

apps/cli/src/node/docker-compose-validator.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ services:
3333
prompt:
3434
image: debian:bookworm-slim
3535
environment:
36-
PROMPT_TXT_02_GRAPHQL: "GraphQL running at http://localhost:${CARTESI_LISTEN_PORT}/graphql"
3736
PROMPT_TXT_03_INSPECT: "Inspect running at http://localhost:${CARTESI_LISTEN_PORT}/inspect/"
3837

3938
traefik-config-generator:
@@ -48,15 +47,4 @@ services:
4847
inspect_server:
4948
loadBalancer:
5049
servers:
51-
- url: "http://validator:10012/inspect"
52-
TRAEFIK_CONFIG_GRAPHQL_SERVER: |
53-
http:
54-
routers:
55-
graphql_server:
56-
rule: "PathPrefix(`/graphql`)"
57-
service: graphql_server
58-
services:
59-
graphql_server:
60-
loadBalancer:
61-
servers:
62-
- url: "http://validator:10000/graphql"
50+
- url: "http://validator:10000/inspect"

0 commit comments

Comments
 (0)