newOS for Developers

Back to Mood Management

Attach Post

beginner

Add content (posts, images, files) to a mood

PUT /mood/attach/post

Overview

The attachToFolder action links an existing post to a mood (folder). This creates an edge relationship in the graph database, making the post accessible within that folder's context.

Multiple attachment methods exist: single post, multiple posts, and progressive handlers for batch operations with progress tracking.

Request

import { 
  attachToFolder,
  attachToFolders,
  massAttachToFolder 
} from "newgraph-signals/actions/folder";

// Attach single post to single folder
await attachToFolder(post, folder);

// Attach single post to multiple folders
await attachToFolders(post, [folder1, folder2]);

// Attach multiple posts to single folder
await massAttachToFolder([post1, post2], folder);

// Progressive handler for UI progress tracking
import { attachToFolderProgressive } from "newgraph-signals/actions/folder";

const progress = attachToFolderProgressive();
progress.exec({
  id: "folder-uuid",        // Target folder
  targetId: "post-uuid",    // Post to attach
  label: "post"             // "post" | "mood" | "user"
});

Parameters

ParameterTypeRequiredDescription
idstringYesTarget folder/mood ID
targetIdstringYesID of entity to attach
labelstringYes"post" | "mood" | "user"

API Methods

LabelAPI EndpointDescription
postPUT /mood/attach/postAttach a post to a mood
moodPUT /mood/attach/moodNest a mood inside another
userPUT /mood/attach/userAssociate a user with a mood

Cache Edge Pattern

// Edge created on attachment
{
  from: "folder-id",
  fromLabel: "folder",
  to: "post-id",
  toLabel: "post",
  label: "attachment"
}

// Query pattern for retrieving folder posts
cache.__EDGES
  .where("__outE")
  .startsWith(`folder+${folderId}+attachment+post`)

Edge Cases

Duplicate Attachments: Attaching the same post twice is idempotent - it won't create duplicate edges.
Cross-Folder: A single post can be attached to multiple folders simultaneously.
Cache Sync: The edge is stored via cachePostAttachment()which uses delayed edge storage for batching.