Skip to content

Commit 02ad111

Browse files
committed
Add documentation and examples for GraphQL run command
Add comprehensive examples showing different ways to use the 'mina internal graphql run' command: - Simple query execution from command line - Query input from stdin (for piping from other commands) - Query input from file (for complex .graphql files) - Query with variables (for parameterized queries) - Query execution on remote nodes (via --node flag) The documentation explains all three input methods and their combinations with optional flags for variables and custom endpoints.
1 parent 9c4ffb5 commit 02ad111

File tree

6 files changed

+79
-1
lines changed

6 files changed

+79
-1
lines changed

website/docs/developers/graphql-api.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ MutationSendZkapp from
9393
GraphqlList from "!!raw-loader!./scripts/cli/graphql-list.sh"; import
9494
GraphqlInspect from "!!raw-loader!./scripts/cli/graphql-inspect.sh"; import
9595
GraphqlInspectRemote from
96-
"!!raw-loader!./scripts/cli/graphql-inspect-remote.sh";
96+
"!!raw-loader!./scripts/cli/graphql-inspect-remote.sh"; import GraphqlRunSimple
97+
from "!!raw-loader!./scripts/cli/graphql-run-simple.sh"; import GraphqlRunStdin
98+
from "!!raw-loader!./scripts/cli/graphql-run-stdin.sh"; import GraphqlRunFile
99+
from "!!raw-loader!./scripts/cli/graphql-run-file.sh"; import
100+
GraphqlRunVariables from "!!raw-loader!./scripts/cli/graphql-run-variables.sh";
101+
import GraphqlRunRemote from "!!raw-loader!./scripts/cli/graphql-run-remote.sh";
97102

98103
# GraphQL API Reference
99104

@@ -775,6 +780,60 @@ To inspect an endpoint on a remote node:
775780
{GraphqlInspectRemote}
776781
</CodeBlock>
777782

783+
#### Run GraphQL Queries
784+
785+
Execute arbitrary GraphQL queries directly from the CLI:
786+
787+
##### Simple query
788+
789+
<CodeBlock language="bash" title="website/docs/developers/scripts/cli/graphql-run-simple.sh">
790+
{GraphqlRunSimple}
791+
</CodeBlock>
792+
793+
This executes the query and returns the formatted JSON response.
794+
795+
##### Query from stdin
796+
797+
<CodeBlock language="bash" title="website/docs/developers/scripts/cli/graphql-run-stdin.sh">
798+
{GraphqlRunStdin}
799+
</CodeBlock>
800+
801+
Useful for piping queries from other commands or scripts.
802+
803+
##### Query from file
804+
805+
<CodeBlock language="bash" title="website/docs/developers/scripts/cli/graphql-run-file.sh">
806+
{GraphqlRunFile}
807+
</CodeBlock>
808+
809+
Convenient for complex queries stored in `.graphql` files.
810+
811+
##### Query with variables
812+
813+
<CodeBlock language="bash" title="website/docs/developers/scripts/cli/graphql-run-variables.sh">
814+
{GraphqlRunVariables}
815+
</CodeBlock>
816+
817+
Variables must be provided as a JSON object. This allows parameterized queries
818+
for dynamic values.
819+
820+
##### Query remote node
821+
822+
<CodeBlock language="bash" title="website/docs/developers/scripts/cli/graphql-run-remote.sh">
823+
{GraphqlRunRemote}
824+
</CodeBlock>
825+
826+
The `run` command supports three input methods:
827+
828+
- **Command line argument**: Pass the query directly as an argument
829+
- **Standard input**: Pipe or redirect queries from stdin
830+
- **File input**: Use `-f` flag to read from a `.graphql` file
831+
832+
You can combine any input method with:
833+
834+
- `-v` or `--variables`: Pass variables as JSON string
835+
- `--node`: Specify a custom GraphQL endpoint URL
836+
778837
These tools are particularly useful for:
779838

780839
- Learning available endpoints without reading documentation
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
# Execute a GraphQL query from a file
3+
mina internal graphql run -f query.graphql
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Execute a GraphQL query on a remote node
3+
mina internal graphql run \
4+
'query { syncStatus }' \
5+
--node http://remote-node:3000/graphql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
# Execute a simple GraphQL query
3+
mina internal graphql run 'query { syncStatus }'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
# Execute a GraphQL query from stdin
3+
echo 'query { version }' | mina internal graphql run
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Execute a GraphQL query with variables
3+
mina internal graphql run \
4+
'query($maxLen: Int!) { bestChain(maxLength: $maxLen) { stateHash } }' \
5+
-v '{"maxLen": 5}'

0 commit comments

Comments
 (0)