Skip to content

Commit 68476b4

Browse files
committed
Add GraphQL introspection and execution commands to CLI
This adds three new commands under 'mina internal graphql' for exploring and interacting with the GraphQL API: Commands: - list: Dynamically discovers and lists all available GraphQL endpoints by querying the server's introspection API. Endpoints are sorted alphabetically with descriptions and argument information. - inspect <endpoint>: Shows detailed schema information for a specific endpoint with user-friendly formatting. Arguments are marked as (required)/(optional) instead of GraphQL type notation. Includes actual curl command examples and live JSON response output. - run [query]: Executes arbitrary GraphQL queries against the node. Supports three input methods (command line argument, stdin, file via -f flag) and variables via -v flag with JSON. Allows querying both local and remote nodes via --node flag. Implementation: All commands use dynamic discovery via GraphQL introspection rather than hardcoded endpoint lists. The implementation includes comprehensive error handling and user-friendly output formatting. Documentation: The documentation includes 10 importable bash scripts demonstrating different use cases: - Basic list and inspect operations - Query execution from command line, stdin, and file - Parameterized queries with variables - Remote node querying All scripts follow the importable pattern using raw-loader for consistency between documentation and tested code. Testing: CI tests verify all commands are available and their help functions work correctly. The test script is integrated into the main tests.yaml workflow to run on every build.
1 parent 146a5b6 commit 68476b4

20 files changed

+1152
-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:

0 commit comments

Comments
 (0)