newOS for Developers

Back to Workflows Hub

Batch Attach

intermediate

Attach a post to multiple moods in one operation.

Endpoint

PUT /mood/attach/post

Called in a loop for each target mood. Uses the attachToFolders helper.

Request / Response

// Request (per mood)
interface AttachRequest {
  postId: string;  // Post to attach
  moodId: string;  // Target mood
}

// Response
interface AttachResponse {
  success: boolean;
  edge: {
    id: string;            // Edge ID in graph
    source: string;        // Post ID
    target: string;        // Mood ID
    label: "attachment";   // Edge type
  }
}

Implementation

import { attachToFolders } from "newgraph-signals";

// Attach a post to multiple moods
const post = { id: "post-123", /* ... */ };
const targetMoods = [
  { id: "mood-1" },
  { id: "mood-2" },
  { id: "mood-3" }
];

await attachToFolders(post, targetMoods);

// Each attachment is processed sequentially
// to maintain edge ordering in the graph

Combined with Upload

import { createPostMultiple, execProgressiveHandler } from "newgraph-signals";

// Upload and attach to multiple moods in one operation
await execProgressiveHandler(createPostMultiple, {
  files: [imageFile],
  foldersToAttach: ["mood-1", "mood-2", "mood-3"],  // Attach to all
  content: "Shared across 3 moods",
  contentMode: "last"
});

// The upload flow handles attachment automatically
// via updateAndAttach() stage

Cache Edge Pattern

Each attachment creates an edge in the local IndexedDB cache:

// Edge key format
"folder" + moodId + "attachment" + "post" + postId

// Example
"folder+mood-123+attachment+post+post-456"

This enables fast local queries without server roundtrips.

Edge Cases

Already attached — Returns existing edge, no duplicate created
Mood doesn't exist — createFolder() is called first if mood is "future"
Permission denied — User must have write access to target mood
Rate limiting — Sequential processing prevents API flooding