Graph Data

Learn how to work with nodes, edges, and dynamic attributes using GraphStore — no built-in types, fully domain-agnostic.

Working with Graph Data

The GraphStore is the central data structure. It manages nodes, edges, and maintains indices for fast lookups. These examples use a biblical genealogy domain, but InferaGraph works with any data model.

Node Types

InferaGraph is domain-agnostic — there are no built-in node types. Your application defines whatever types and attributes it needs via plain key-value attributes.

// Your app defines its own types — InferaGraph doesn't prescribe any
const myNode = {
  id: 'abraham',
  attributes: {
    type: 'person',        // your app's concept
    name: 'Abraham',
    era: 'Patriarchs',
  }
};

Biblical Genealogy

person, place, event, group

Map family trees, journeys, and events across scripture

Infrastructure

service, server, database, queue

Monitor dependencies and health across your stack

Social Network

user, post, community, event

Model connections between people and content

Node Attributes

// NodeAttributes is an open record — define whatever your domain needs
type NodeAttributes = { [key: string]: unknown };

// Example: a biblical genealogy app might define
interface BibleNodeAttributes extends NodeAttributes {
  type: 'person' | 'place' | 'event';
  name: string;
  era?: string;
  description?: string;
}

// Example: an infrastructure app might define
interface ServiceNode extends NodeAttributes {
  type: 'service';
  name: string;
  status: 'healthy' | 'degraded' | 'down';
  port: number;
}

Adding and Removing Nodes

import { useInferaGraph, InferaGraph } from '@inferagraph/core';
import { useEffect } from 'react';

function GraphSetup() {
  const { graphStore } = useInferaGraph();

  useEffect(() => {
    // Add nodes — attributes are whatever your app needs
    graphStore.addNode('abraham', {
      type: 'person',
      name: 'Abraham',
      era: 'Patriarchs',
    });

    graphStore.addNode('sarah', {
      type: 'person',
      name: 'Sarah',
      era: 'Patriarchs',
    });

    graphStore.addNode('canaan', {
      type: 'place',
      name: 'Canaan',
    });

    // Add edges — relationship types are also yours to define
    graphStore.addEdge('e1', 'abraham', 'sarah', {
      type: 'husband_of',
    });

    graphStore.addEdge('e2', 'abraham', 'canaan', {
      type: 'traveled_to',
    });
  }, [graphStore]);

  return <InferaGraph />;
}