MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / cypher_helper

Function cypher_helper

src/codegraphcontext/cli/cli_helpers.py:533–567  ·  view source on GitHub ↗

Executes a read-only Cypher query.

(query: str, context: Optional[str] = None)

Source from the content-addressed store, hash-verified

531
532
533def cypher_helper(query: str, context: Optional[str] = None):
534 """Executes a read-only Cypher query."""
535 services = _initialize_services(context)
536 if not all(services[:3]):
537 _fail_services_init()
538
539 db_manager, _, _, ctx = services
540
541 from ..utils.cypher_readonly import is_read_only_cypher, read_only_rejection_message
542
543 if not is_read_only_cypher(query):
544 console.print(f"[bold red]Error:[/bold red] {read_only_rejection_message()}")
545 db_manager.close_driver()
546 raise typer.Exit(code=1)
547
548 backend = getattr(db_manager, "get_backend_type", lambda: "neo4j")()
549 # Neo4j honours default_access_mode natively; FalkorDB routes READ sessions
550 # through GRAPH.RO_QUERY for server-enforced read-only execution.
551 session_kwargs = (
552 {"default_access_mode": "READ"}
553 if backend in ("neo4j", "falkordb", "falkordb-remote")
554 else {}
555 )
556
557 try:
558 with db_manager.get_driver().session(**session_kwargs) as session:
559 result = session.run(query)
560 records = [record.data() for record in result]
561 console.print(json.dumps(records, indent=2))
562 except Exception as e:
563 _print_query_exception(e, query)
564 db_manager.close_driver()
565 raise typer.Exit(code=1)
566 finally:
567 db_manager.close_driver()
568
569
570def cypher_helper_visual(query: str, context: Optional[str] = None):

Callers 2

query_graphFunction · 0.85
cypher_legacyFunction · 0.85

Calls 11

_initialize_servicesFunction · 0.85
_fail_services_initFunction · 0.85
is_read_only_cypherFunction · 0.85
_print_query_exceptionFunction · 0.85
printMethod · 0.80
close_driverMethod · 0.45
sessionMethod · 0.45
get_driverMethod · 0.45
runMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected