fix: Link creation broken due to ID vs URI mismatch
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user