Skip to content

Commit e11aad6

Browse files
authored
Merge pull request #1565 from o1-labs/dw/mina-cli-graphql-endpoints
Add GraphQL introspection and execution commands to CLI
2 parents 146a5b6 + 3ebd954 commit e11aad6

21 files changed

+1160
-1
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
MINA_BIN="${MINA_BIN:-./target/release/mina}"
6+
# Convert to absolute path if it's a relative path
7+
if [[ "${MINA_BIN}" != /* ]]; then
8+
MINA_BIN="$(pwd)/${MINA_BIN}"
9+
fi
10+
11+
# Add the directory containing the mina binary to PATH
12+
# so documentation scripts can find 'mina' command
13+
MINA_DIR="$(dirname "${MINA_BIN}")"
14+
export PATH="${MINA_DIR}:${PATH}"
15+
16+
SCRIPT_DIR="website/docs/developers/scripts/cli"
17+
QUERY_FILE="website/docs/developers/scripts/graphql-api/queries/query/sync-status.graphql"
18+
GRAPHQL_NODE="${GRAPHQL_NODE:-https://mina-rust-plain-3.gcp.o1test.net/graphql}"
19+
20+
echo "Testing that 'mina internal graphql' commands are available..."
21+
22+
# Test 'mina internal' command exists
23+
"${MINA_BIN}" internal --help > /dev/null || {
24+
echo "ERROR: 'mina internal' command not found"
25+
exit 1
26+
}
27+
28+
# Test 'mina internal graphql' command exists
29+
"${MINA_BIN}" internal graphql --help > /dev/null || {
30+
echo "ERROR: 'mina internal graphql' command not found"
31+
exit 1
32+
}
33+
34+
# Test 'mina internal graphql list' command exists
35+
"${MINA_BIN}" internal graphql list --help > /dev/null || {
36+
echo "ERROR: 'mina internal graphql list' command not found"
37+
exit 1
38+
}
39+
40+
# Test 'mina internal graphql inspect' command exists
41+
"${MINA_BIN}" internal graphql inspect --help > /dev/null || {
42+
echo "ERROR: 'mina internal graphql inspect' command not found"
43+
exit 1
44+
}
45+
46+
# Test 'mina internal graphql run' command exists
47+
"${MINA_BIN}" internal graphql run --help > /dev/null || {
48+
echo "ERROR: 'mina internal graphql run' command not found"
49+
exit 1
50+
}
51+
52+
echo ""
53+
echo "Testing documentation scripts execution against ${GRAPHQL_NODE}..."
54+
55+
# Function to test a script against the o1Labs node
56+
test_script() {
57+
local script="$1"
58+
local extra_args="${2:-}"
59+
60+
if [[ ! -f "${SCRIPT_DIR}/${script}" ]]; then
61+
echo "ERROR: Script ${script} not found"
62+
exit 1
63+
fi
64+
65+
echo "Running ${script}..."
66+
67+
# Export MINA_BIN for scripts to use, and add --node flag if needed
68+
export MINA_BIN
69+
if [[ -n "${extra_args}" ]]; then
70+
# Run script with modifications
71+
if output=$(bash -c "cd ${SCRIPT_DIR} && ${extra_args}" 2>&1); then
72+
echo " SUCCESS: ${script} executed successfully"
73+
return 0
74+
else
75+
echo "ERROR: ${script} failed:"
76+
echo "$output"
77+
exit 1
78+
fi
79+
else
80+
# Run script as-is
81+
if output=$(bash "${SCRIPT_DIR}/${script}" 2>&1); then
82+
echo " SUCCESS: ${script} executed successfully"
83+
return 0
84+
else
85+
echo "ERROR: ${script} failed:"
86+
echo "$output"
87+
exit 1
88+
fi
89+
fi
90+
}
91+
92+
# Test all documentation scripts against the o1Labs node
93+
# Scripts that don't have --node need it added
94+
test_script "graphql-list.sh" "${MINA_BIN} internal graphql list --node ${GRAPHQL_NODE}"
95+
test_script "graphql-inspect.sh" "${MINA_BIN} internal graphql inspect syncStatus --node ${GRAPHQL_NODE}"
96+
test_script "graphql-inspect-remote.sh"
97+
test_script "graphql-run-simple.sh" "${MINA_BIN} internal graphql run 'query { syncStatus }' --node ${GRAPHQL_NODE}"
98+
test_script "graphql-run-stdin.sh" "echo 'query { version }' | ${MINA_BIN} internal graphql run --node ${GRAPHQL_NODE}"
99+
100+
# graphql-run-file.sh needs a query.graphql file in the current directory
101+
echo "Running graphql-run-file.sh..."
102+
if [[ ! -f "${QUERY_FILE}" ]]; then
103+
echo "ERROR: Query file ${QUERY_FILE} not found"
104+
exit 1
105+
fi
106+
# Create symlink in current directory for the script
107+
ln -sf "${PWD}/${QUERY_FILE}" query.graphql
108+
if output=$(${MINA_BIN} internal graphql run -f query.graphql --node "${GRAPHQL_NODE}" 2>&1); then
109+
echo " SUCCESS: graphql-run-file.sh executed successfully"
110+
else
111+
echo "ERROR: graphql-run-file.sh failed:"
112+
echo "$output"
113+
rm -f query.graphql
114+
exit 1
115+
fi
116+
rm -f query.graphql
117+
118+
test_script "graphql-run-variables.sh" "${MINA_BIN} internal graphql run 'query(\$maxLen: Int!) { bestChain(maxLength: \$maxLen) { stateHash } }' -v '{\"maxLen\": 5}' --node ${GRAPHQL_NODE}"
119+
test_script "graphql-run-remote.sh"
120+
121+
echo ""
122+
echo "SUCCESS: All 'mina internal graphql' commands and documentation scripts tested"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
MINA_BIN="${MINA_BIN:-./target/release/mina}"
6+
# Convert to absolute path if it's a relative path
7+
if [[ "${MINA_BIN}" != /* ]]; then
8+
MINA_BIN="$(pwd)/${MINA_BIN}"
9+
fi
10+
11+
# Add the directory containing the mina binary to PATH
12+
# so documentation scripts can find 'mina' command
13+
MINA_DIR="$(dirname "${MINA_BIN}")"
14+
export PATH="${MINA_DIR}:${PATH}"
15+
16+
OCAML_NODE="${OCAML_NODE:-https://devnet-plain-1.gcp.o1test.net/graphql}"
17+
SCRIPT_DIR="website/docs/developers/scripts/cli"
18+
19+
echo "Testing OCaml-specific endpoints..."
20+
21+
# Test protocolState endpoint (OCaml-specific)
22+
# Uses the command from the documentation script
23+
SCRIPT_FILE="${SCRIPT_DIR}/graphql-run-ocaml-protocolstate.sh"
24+
if [[ ! -f "${SCRIPT_FILE}" ]]; then
25+
echo "ERROR: Script file ${SCRIPT_FILE} not found"
26+
exit 1
27+
fi
28+
29+
echo "Testing protocolState endpoint using ${SCRIPT_FILE}..."
30+
# Extract the command from the script and replace mina with MINA_BIN and the node URL
31+
COMMAND=$(grep -v "^#" "${SCRIPT_FILE}" | sed "s|mina|${MINA_BIN}|" | sed "s|https://devnet-plain-1.gcp.o1test.net/graphql|${OCAML_NODE}|")
32+
33+
if output=$(eval "${COMMAND}" 2>&1); then
34+
echo " SUCCESS: protocolState endpoint query executed successfully"
35+
else
36+
echo "ERROR: protocolState endpoint query failed:"
37+
echo "$output"
38+
exit 1
39+
fi
40+
41+
echo "All OCaml-specific endpoint tests passed!"

.github/workflows/tests.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ jobs:
232232
233233
echo "Build info verification passed!"
234234
235+
- name: Test mina internal graphql commands (Rust node)
236+
run: ./.github/scripts/test-cli-graphql-commands.sh
237+
238+
- name: Test mina internal graphql commands (OCaml node)
239+
env:
240+
GRAPHQL_NODE: https://devnet-plain-1.gcp.o1test.net/graphql
241+
run: ./.github/scripts/test-cli-graphql-commands.sh
242+
243+
- name: Test OCaml-specific GraphQL endpoints
244+
run: ./.github/scripts/test-ocaml-specific-endpoints.sh
245+
235246
- name: Upload binaries
236247
uses: actions/upload-artifact@v4
237248
with:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Added
1616

17+
- **CLI**: add GraphQL introspection and execution commands under `mina
18+
internal graphql`. Three new commands enable dynamic endpoint discovery
19+
(`list`), detailed schema inspection (`inspect <endpoint>`), and arbitrary
20+
query execution (`run [query]`) with support for multiple input methods
21+
(command line, stdin, file) and variables. All commands use GraphQL
22+
introspection API for dynamic discovery without hardcoded endpoints. CI tests
23+
validate commands against o1Labs infrastructure
24+
([#1565](https://github.com/o1-labs/mina-rust/pull/1565))
1725
- **CI**: add devnet and mainnet Caml nodes to remote GraphQL test suite to
1826
ensure compatibility between Rust and OCaml implementations
1927
([#1542](https://github.com/o1-labs/mina-rust/pull/1542))

0 commit comments

Comments
 (0)