This command-line tool allows you to run arbitrary DQL (Dgraph Query Language) queries against a modusGraph database, either in local file-based mode or (optionally) against a remote Dgraph-compatible endpoint.
- Go 1.24 or higher
- Access to a directory containing a modusGraph database (created by modusGraph)
# Navigate to the cmd/query directory
cd cmd/query
# Run directly
go run main.go --dir /path/to/modusgraph [options]
# Or build and then run
go build -o modusgraph-query
./modusgraph-query --dir /path/to/modusgraph [options]
The tool reads a DQL query from standard input and prints the JSON response to standard output.
Usage of ./main:
--dir string Directory where the modusGraph database is stored (required)
--pretty Pretty-print the JSON output (default true)
--timeout Query timeout duration (default 30s)
-v int Verbosity level for logging (e.g., -v=1, -v=2)
echo '{ q(func: has(name@en), first: 10) { id: uid name@en } }' | go run main.go --dir /tmp/modusgraph
echo '{ q(func: has(name@en), first: 10) { id: uid name@en } }' | go run main.go --dir /tmp/modusgraph -v 1
go build -o modusgraph-query
cat query.dql | ./modusgraph-query --dir /tmp/modusgraph
- The
--dir
flag is required and must point to a directory initialized by modusGraph. - The query must be provided via standard input.
- Use the
-v
flag to control logging verbosity (higher values show more log output). - Use the
--pretty=false
flag to disable pretty-printing of the JSON response. - The tool logs query timing and errors to standard error.
{
"q": [
{ "id": "0x2", "name@en": "Ivan Sen" },
{ "id": "0x3", "name@en": "Peter Lord" }
]
}
For more advanced usage and integration, see the main modusGraph documentation.