Skip to content

Latest commit

 

History

History
116 lines (88 loc) · 2.54 KB

File metadata and controls

116 lines (88 loc) · 2.54 KB

Queries

Common Cypher Snippets

List all functions

MATCH (f:Function)
RETURN f.project AS project, f.name AS function, f.file_uid AS file
ORDER BY project, function
LIMIT 100

Function fan-in / fan-out (intra-project calls)

Uses CALLS_FUNCTION edges which represent resolved function-to-function calls within the same project. CALLS edges point to unresolved Symbol nodes and are not suitable for coupling metrics.

MATCH (f:Function)
OPTIONAL MATCH (f)<-[:CALLS_FUNCTION]-(inbound:Function)
OPTIONAL MATCH (f)-[:CALLS_FUNCTION]->(outbound:Function)
RETURN f.project AS project,
       f.name AS function,
       count(DISTINCT inbound) AS fan_in,
       count(DISTINCT outbound) AS fan_out
ORDER BY (count(DISTINCT inbound) + count(DISTINCT outbound)) DESC
LIMIT 50

Most-called functions (highest fan-in)

MATCH (caller:Function)-[:CALLS_FUNCTION]->(callee:Function)
RETURN callee.project AS project, callee.name AS name, count(caller) AS fan_in
ORDER BY fan_in DESC
LIMIT 20

Duplicate function signatures

MATCH (f:Function)
WITH f.signature_hash AS sig, collect(f.name) AS names, count(*) AS copies
WHERE copies > 1
RETURN sig, copies, names
ORDER BY copies DESC

Transitive callers of a function

MATCH (target:Function {name: $symbol})
MATCH p = (caller:Function)-[:CALLS_FUNCTION*1..4]->(target)
WITH caller, min(length(p)) AS hops
RETURN caller.project, caller.name, caller.file_uid, hops
ORDER BY hops, caller.name
LIMIT 100

Files importing a module

MATCH (f:File)-[:IMPORTS]->(m:Module {name: $module})
RETURN f.project AS project, f.rel_path AS file
ORDER BY project, file

Cross-project shared symbols

Find symbol names called by functions in both project A and project B:

MATCH (f:Function {project: $project_a})-[:CALLS]->(s:Symbol)
      <-[:CALLS]-(g:Function {project: $project_b})
RETURN DISTINCT s.name AS shared_symbol
ORDER BY shared_symbol
LIMIT 50

Node counts by label

MATCH (n)
RETURN labels(n)[0] AS label, count(n) AS count
ORDER BY count DESC

Edge counts by type

MATCH ()-[r]->()
RETURN type(r) AS rel, count(r) AS count
ORDER BY count DESC

Using the Query Command

Run inline Cypher:

codegraphx query "MATCH (f:Function) RETURN f.name LIMIT 10"

Add --safe to enable the write-guard for ad-hoc sessions:

codegraphx query "MATCH (f:Function) RETURN f.name LIMIT 10" --safe

Run from a .cypher file:

codegraphx query path/to/query.cypher