From e91886a1ce29a268216bbe935bde350fd11174ff Mon Sep 17 00:00:00 2001 From: Albert Date: Mon, 10 Nov 2025 01:17:54 +0000 Subject: [PATCH] fix: Link creation broken due to ID vs URI mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed bug where links between nodes weren't being created. Root Cause: - UI sends node IDs in links array (e.g., "node:xxxxx") - API query expected ATProto URIs (e.g., "at://did:plc:.../app.bsky.feed.post/...") - Query: WHERE atp_uri IN $links never matched - Result: Zero links created in database Fix: - Changed query to: WHERE id IN $links - Now correctly matches node IDs from UI - Added logging to track link creation - Updated comments to clarify expected format Impact: Links selected in the edit UI will now be properly created and visible as connections in the 3D thought galaxy visualization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/nodes/route.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/nodes/route.ts b/app/api/nodes/route.ts index c923174..ec92f63 100644 --- a/app/api/nodes/route.ts +++ b/app/api/nodes/route.ts @@ -257,14 +257,17 @@ export async function POST(request: NextRequest) { // Handle linking if (links && links.length > 0) { - // Find the corresponding cache nodes for the AT-URIs + // Links array contains node IDs (e.g., "node:xxxxx") from the UI + // Verify they belong to this user before creating relations const targetNodesResult = await db.query<[Array<{ id: string }>]>( - 'SELECT id FROM node WHERE user_did = $did AND atp_uri IN $links', + 'SELECT id FROM node WHERE user_did = $did AND id IN $links', { did: userDid, links: links } ); const targetNodes = targetNodesResult[0] || []; + console.log(`[POST /api/nodes] Creating ${targetNodes.length} link relations`); + // Create graph relations for (const targetNode of targetNodes) { await db.query('RELATE $from->links_to->$to', {