/** * HTTP client for the graph endpoint (R3.5.1 backend). * * Uses the shared Docmost `api` axios instance (same base "/api" and cookie auth) * rather than the bridge client — the graph endpoint lives on the Docmost server. */ import api from "@/lib/api-client"; export interface GraphNode { id: string; label: string | null; /** URL slug for /p/:slug navigation — null when the page has no slug yet */ slug: string | null; type: "page"; spaceId: string; spaceName: string | null; icon: string | null; isOrphan: boolean; metrics: { inDegree: number; outDegree: number; }; } export interface GraphEdge { id: string; source: string; target: string; type: "wikilink" | "mention" | "database_embed" | "parent_child"; weight: number; } export interface GraphMeta { totalNodes: number; totalEdges: number; workspaceId: string; rootPageId?: string; depth?: number; truncated: boolean; } export interface GraphResponse { nodes: GraphNode[]; edges: GraphEdge[]; meta: GraphMeta; } export interface GraphQueryParams { spaceId?: string; pageId?: string; depth?: number; types?: Array<"wikilink" | "mention" | "database_embed">; includeOrphans?: boolean; } export async function fetchGraph( params: GraphQueryParams, ): Promise { const query: Record = {}; if (params.spaceId) query.spaceId = params.spaceId; if (params.pageId) query.pageId = params.pageId; if (params.depth !== undefined) query.depth = String(params.depth); if (params.types && params.types.length > 0) query.types = params.types.join(","); if (params.includeOrphans !== undefined) query.includeOrphans = String(params.includeOrphans); const qs = new URLSearchParams(query).toString(); const url = qs ? `/v1/graph?${qs}` : "/v1/graph"; return api.get(url) as unknown as Promise; }