Run Cypher queries from the rdx console - #883
Open
paracycle wants to merge 1 commit into
Open
Conversation
paracycle
force-pushed
the
uk_add_cypher_query_engine
branch
from
June 25, 2026 20:31
f6e2615 to
7e08a7b
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
2 times, most recently
from
June 25, 2026 20:33
e8308d4 to
9306fe5
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
6 times, most recently
from
July 3, 2026 21:02
c41173d to
19a7ce6
Compare
paracycle
force-pushed
the
uk_add_cypher_query_engine
branch
from
July 3, 2026 21:16
ded5eb9 to
4fa3719
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
2 times, most recently
from
July 3, 2026 21:32
6132b4a to
63488b8
Compare
paracycle
force-pushed
the
uk_add_cypher_query_engine
branch
3 times, most recently
from
July 3, 2026 21:56
85bbbba to
cc553f6
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
2 times, most recently
from
July 8, 2026 16:50
622970f to
7b27f69
Compare
paracycle
changed the base branch from
uk_add_cypher_query_engine
to
uk_query_object_results
July 8, 2026 16:50
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 8, 2026 18:26
d68b816 to
51b4f05
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 8, 2026 18:28
7b27f69 to
c3e332e
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 8, 2026 20:05
51b4f05 to
2bb59e0
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 8, 2026 20:06
c3e332e to
d2e3c09
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 8, 2026 20:19
2bb59e0 to
1de091c
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 8, 2026 20:19
d2e3c09 to
825248e
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 9, 2026 20:13
1de091c to
ae8fcbd
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 9, 2026 20:13
825248e to
10e1f88
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 9, 2026 20:56
ae8fcbd to
9e80825
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 9, 2026 20:57
10e1f88 to
dc2c413
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 9, 2026 21:17
9e80825 to
5fb40e7
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 9, 2026 21:18
dc2c413 to
47450a6
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 9, 2026 22:39
5fb40e7 to
933bf3d
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 9, 2026 22:40
47450a6 to
140980d
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
from
July 16, 2026 20:18
933bf3d to
a22a461
Compare
paracycle
force-pushed
the
uk_query_object_results
branch
3 times, most recently
from
July 29, 2026 17:24
bdddecc to
6865c54
Compare
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 29, 2026 17:30
140980d to
af4305c
Compare
Morriar
reviewed
Jul 29, 2026
paracycle
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 29, 2026 21:50
af4305c to
5bf2f17
Compare
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
force-pushed
the
uk_rdx_console_query_mode
branch
from
July 31, 2026 17:55
5bf2f17 to
3ecad72
Compare
Morriar
reviewed
Aug 6, 2026
Morriar
left a comment
Contributor
There was a problem hiding this comment.
Found one CI issue to fix before this lands.
Morriar
approved these changes
Aug 6, 2026
| # 1.13. Requiring an older or absent IRB raises `LoadError` (`Gem::LoadError` is one), which | ||
| # `exe/rdx` turns into a friendly message rather than a backtrace. | ||
| gem "irb", ">= 1.13" | ||
| require "irb" |
Contributor
There was a problem hiding this comment.
You may need to require "fiddle" to fix the Windows build?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Let
rdx consolerun Cypher directly, addressing the "query mode" idea from #868's review.What it does
The session is a stock IRB workspace with
graphin scope, so plain Ruby works as always (graph["Foo"]). On top of that it registers three things through IRB's own extension APIs:querytakes the rest of the line verbatim, so the Cypher needs neither quoting nor to be valid Ruby. Rather than swapping the REPL's evaluator for a modal toggle, Cypher lines are simply prefixed withquery— the clean, idiomatic IRB realization of a query mode.runis the programmatic entry point andquerythe interactive quick-look; they are deliberately separate rather than one delegating to the other.How it hooks into IRB
IRB has two distinct registration APIs, and this PR uses each for what it's for:
IRB::Command.register— forquery/schema, which consume the rest of the line verbatim.IRB::HelperMethod.register— forrun, which must stay an ordinary expression so its value can be assigned.The session workspace is IRB's own
IRB::WorkSpace.new, not a hand-rolled binding. That matters for three reasons:selfismainand the cref isObject, soclass Foo; endat the prompt defines::Foo. Abindingcaptured insideclass << selfwould define#<Class:Rubydex::Console>::Fooinstead.TOPLEVEL_BINDINGwould inherit every top-level local ofexe/rdx— includingqueryandschema, and a local shadows the IRB command of the same name._,helpand the rest of IRB's conveniences behave exactly as in stockirb.Only
graphis injected, viaIRB::WorkSpace#local_variable_set.Notes
lib/rubydex/console.rb.Console.run(objects),Console.render(formatted string) andConsole.describe_schemaare plain module methods, so they are testable without driving IRB.gem "irb", ">= 1.13"at load. A missing or older IRB raisesLoadError(Gem::MissingSpecVersionErroris one), whichexe/rdxturns intoInteractive mode requires \irb` >= 1.13 to be in the bundle` rather than a backtrace. IRB is not declared in the gemspec, which carries no runtime dependencies.runreturns the rich objects fromQuery#run(Return Cypher query results as graph objects #873): node columns come back as liveDeclaration/Definition/Documenthandles.Verification
test/console_test.rb— 8 runs, 29 assertions, 0 failures. Includes a regression test that the session workspace evaluates at top level (self == main, onlygraphinjected,class Probe; enddefines::Probe); it fails if a hand-rolled binding is reintroduced.rubocopclean.rdx consoleagainst this repo:self→main,local_variables→[:_, :__, :graph],Foo.name→"Foo",run("MATCH (c:Class {name: 'Rubydex::Graph'}) RETURN c.name")→[{"c.name" => "Rubydex::Graph"}], andquery/schemaboth print their tables.irbinstalled, and with onlyirb1.12 installed,rdx consoleaborts cleanly with exit status 1.