This repository has no description
1import { cache } from 'react';
2import { createSembleClient } from '@/services/client.apiClient';
3import { verifySessionOnClient } from '@/lib/auth/dal';
4
5/**
6 * Fetch a specific page of graph data from the backend
7 * Returns nodes and edges for the specified page with pagination metadata
8 *
9 * @param page - Page number (1-indexed, defaults to 1)
10 * @param limit - Number of nodes per page (defaults to 300)
11 */
12export const getGraphDataPage = cache(
13 async (page: number = 1, limit: number = 300) => {
14 // Verify authentication - graph data is personalized
15 const session = await verifySessionOnClient({ redirectOnFail: true });
16 if (!session) throw new Error('No session found');
17
18 const client = createSembleClient();
19 const response = await client.getGraphData({ page, limit });
20
21 return response;
22 },
23);
24
25/**
26 * Fetch all graph data from the backend (deprecated - use getGraphDataPage for better performance)
27 * Returns all nodes and edges for the current user's knowledge graph
28 *
29 * @deprecated Use getGraphDataPage instead for incremental loading
30 */
31export const getGraphData = cache(async () => {
32 // For backward compatibility, fetch page 1 with a large limit
33 return getGraphDataPage(1, 10000);
34});
35
36/**
37 * Fetch URL-centric sub-graph with depth-based traversal
38 * Returns all nodes and edges within N hops of the target URL
39 *
40 * @param url - Target URL to center the sub-graph around
41 * @param depth - Number of edge hops to traverse (1-5, defaults to 1)
42 */
43export const getUrlGraphData = cache(async (url: string, depth: number = 1) => {
44 // Verify authentication - graph data is personalized
45 const session = await verifySessionOnClient({ redirectOnFail: true });
46 if (!session) throw new Error('No session found');
47
48 const client = createSembleClient();
49 const response = await client.getUrlGraphData({ url, depth });
50
51 return response;
52});