Skip to content

Run Cypher queries from the rdx console#883

Open
paracycle wants to merge 2 commits into
uk_query_object_resultsfrom
uk_rdx_console_query_mode
Open

Run Cypher queries from the rdx console#883
paracycle wants to merge 2 commits into
uk_query_object_resultsfrom
uk_rdx_console_query_mode

Conversation

@paracycle

Copy link
Copy Markdown
Member

Goal

Let rdx console run Cypher directly, addressing the "query mode" idea from #868's review.

Stacked on #868 (base uk_add_cypher_query_engine).

What it does

On top of the normal IRB session (with graph in scope for Ruby, e.g. graph["Foo"]), it registers two commands:

rubydex> query MATCH (n:Class|Module) RETURN n.name ORDER BY n.name
rubydex> schema

The query command takes the rest of the line verbatim, so the Cypher doesn't need to be valid Ruby or quoted. Rather than swapping the REPL's evaluator for a modal toggle, Cypher lines are simply prefixed with query — the clean, idiomatic IRB realization of a query mode.

Notes

  • Console logic is extracted into lib/rubydex/console.rb; the query path lives in Console.run_query so it's testable without driving IRB.
  • IRB stays a soft dependency: it's a default gem, so it's not declared in the gemspec. The commands register only when the installed IRB exposes the command API (>= 1.13); on older IRB the console degrades to a plain Ruby session.
  • Currently uses Query#render (string output). Once an object-returning Query#run lands, query could return real handle objects instead of a printed table.

Verification

rake ruby_test TEST=test/console_test.rb (7 tests), rubocop clean, live console smoke test.

@paracycle
paracycle requested a review from a team as a code owner June 25, 2026 20:25
@paracycle
paracycle force-pushed the uk_add_cypher_query_engine branch from f6e2615 to 7e08a7b Compare June 25, 2026 20:31
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch 2 times, most recently from e8308d4 to 9306fe5 Compare June 25, 2026 20:33
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch 6 times, most recently from c41173d to 19a7ce6 Compare July 3, 2026 21:02
@paracycle
paracycle force-pushed the uk_add_cypher_query_engine branch from ded5eb9 to 4fa3719 Compare July 3, 2026 21:16
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch 2 times, most recently from 6132b4a to 63488b8 Compare July 3, 2026 21:32
@paracycle
paracycle force-pushed the uk_add_cypher_query_engine branch 3 times, most recently from 85bbbba to cc553f6 Compare July 3, 2026 21:56
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch 2 times, most recently from 622970f to 7b27f69 Compare July 8, 2026 16:50
@paracycle
paracycle changed the base branch from uk_add_cypher_query_engine to uk_query_object_results July 8, 2026 16:50
@paracycle
paracycle force-pushed the uk_query_object_results branch from d68b816 to 51b4f05 Compare July 8, 2026 18:26
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from 7b27f69 to c3e332e Compare July 8, 2026 18:28
@paracycle
paracycle force-pushed the uk_query_object_results branch from 51b4f05 to 2bb59e0 Compare July 8, 2026 20:05
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from c3e332e to d2e3c09 Compare July 8, 2026 20:06
@paracycle
paracycle force-pushed the uk_query_object_results branch from 2bb59e0 to 1de091c Compare July 8, 2026 20:19
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from d2e3c09 to 825248e Compare July 8, 2026 20:19
@paracycle
paracycle force-pushed the uk_query_object_results branch from 1de091c to ae8fcbd Compare July 9, 2026 20:13
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from 825248e to 10e1f88 Compare July 9, 2026 20:13
@paracycle
paracycle force-pushed the uk_query_object_results branch from ae8fcbd to 9e80825 Compare July 9, 2026 20:56
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from 10e1f88 to dc2c413 Compare July 9, 2026 20:57
@paracycle
paracycle force-pushed the uk_query_object_results branch from 9e80825 to 5fb40e7 Compare July 9, 2026 21:17
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from dc2c413 to 47450a6 Compare July 9, 2026 21:18
Add an object-returning `Rubydex::Query#run(graph)` alongside the
string-returning `Query#render`. Where `render` formats rows into a table
or JSON string, `run` returns an `Array<Hash>` whose values are real Ruby
objects — including `Declaration`/`Definition`/`Document` handles for node
columns, and Hashes for map projections — so callers can navigate the graph
directly instead of re-parsing formatted text.

Targets `cypher-parser` 0.8:
- structured node results (`CypherValue::Node`) surfaced through the FFI as
  handle-buildable cells, plus `CypherValue::Map` -> Ruby Hash.
- implement the new `GraphProvider::expand_in` for the cheap, exact reverse
  edges (a definition's document, a declaration's definitions), turning
  those incoming traversals from a whole-graph build into direct lookups;
  other edges fall back to the default reverse-adjacency build.
@paracycle
paracycle force-pushed the uk_query_object_results branch from 5fb40e7 to 933bf3d Compare July 9, 2026 22:39
Add `Rubydex::Console`, which backs `rdx console` with an IRB session that
keeps `graph` in scope (for Ruby, e.g. `graph["Foo"]`) and registers two
Cypher commands via IRB's modern command API:

  rubydex> query MATCH (n:Class|Module) RETURN n.name ORDER BY n.name
  rubydex> schema

The `query` command takes the rest of the line verbatim, so the Cypher
does not need to be valid Ruby or quoted. This is the clean, idiomatic
"query mode": rather than swapping the REPL's evaluator, Cypher lines are
prefixed with `query`.

- Extract the console out of exe/rdx into lib/rubydex/console.rb; the
  query-running logic lives in Console.run_query so it is testable without
  driving IRB.
- Treat IRB as a soft, runtime dependency rather than a gemspec one. IRB is
  a default gem, so it is not declared in the gemspec; the Cypher commands
  register only when the installed IRB exposes the command API (>= 1.13),
  and the console degrades to a plain Ruby session on older versions.
@paracycle
paracycle force-pushed the uk_rdx_console_query_mode branch from 47450a6 to 140980d Compare July 9, 2026 22:40
@paracycle
paracycle force-pushed the uk_query_object_results branch from 933bf3d to a22a461 Compare July 16, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant