refactor(api): use executeCypher directly in buildGraph

Add public executeCypher(repoName, query) method to LocalBackend,
bypassing the callTool string dispatch and resolving the repo handle
directly. Update buildGraph in api.ts to call it instead of going
through callTool('cypher', ...) on every query.
This commit is contained in:
Paul Robello 2026-02-23 07:23:46 -08:00
parent 884b6265cf
commit aa12d17504
2 changed files with 10 additions and 5 deletions

View file

@ -636,6 +636,11 @@ export class LocalBackend {
}
}
async executeCypher(repoName: string, query: string): Promise<any> {
const repo = await this.resolveRepo(repoName);
return this.cypher(repo, { query });
}
private async cypher(repo: RepoHandle, params: { query: string }): Promise<any> {
await this.ensureInitialized(repo.id);

View file

@ -39,7 +39,7 @@ const buildGraph = async (
query = `MATCH (n:${table}) RETURN n.id AS id, n.name AS name, n.filePath AS filePath, n.startLine AS startLine, n.endLine AS endLine, n.content AS content`;
}
const result = await backend.callTool('cypher', { repo: repoName, query });
const result = await backend.executeCypher(repoName, query);
// cypher returns the rows directly (array), or { error } on failure
const rows = Array.isArray(result) ? result : [];
@ -71,10 +71,10 @@ const buildGraph = async (
const relationships: GraphRelationship[] = [];
try {
const relResult = await backend.callTool('cypher', {
repo: repoName,
query: `MATCH (a)-[r:CodeRelation]->(b) RETURN a.id AS sourceId, b.id AS targetId, r.type AS type, r.confidence AS confidence, r.reason AS reason, r.step AS step`,
});
const relResult = await backend.executeCypher(
repoName,
`MATCH (a)-[r:CodeRelation]->(b) RETURN a.id AS sourceId, b.id AS targetId, r.type AS type, r.confidence AS confidence, r.reason AS reason, r.step AS step`,
);
const relRows = Array.isArray(relResult) ? relResult : [];
for (const row of relRows) {