GraphApi mascot

Introduction to Graph API

Graph API is an ergonomic library for working with in memory graphs in Rust that provides a flexible and type-safe way to interact with graph data structures.

Heavily inspired by Apache TinkerPop, it offers an iterator-like interface specifically designed for graph traversal and manipulation.

Overview

This library offers a unified interface for working with different types of graphs while maintaining strong type safety and ergonomic usage patterns. It includes features for graph traversal, modification, and custom extensions.

Advantages

  • Iterator-like interface for graphs: Intuitive API that feels familiar to Rust developers
  • Works with multiple backends:
    • simple graph - A simple adjacency list based graph with index support
    • petgraph - An excellent established graph library
    • You can also create your own!
  • Composable operations: Chain graph operations together in a fluent, declarative style
  • Separation of graph model and implementation: Define your domain model once and use it with any supported backend

Key Features

  • Type-safe graph operations: Work with graph data in a strongly-typed manner
  • Flexible vertex and edge traversal: Explore graph relationships with powerful walker API
  • Custom graph implementations support: Adapt to various graph storage backends
  • Derive macros for extending graph functionality: Automatically generate boilerplate code
  • Comprehensive testing utilities: Including fuzzing support

Example

    // Find a person using the username index (exact match)
    let bryn = graph
        .walk()
        .vertices(Vertex::person_by_username("bryn123"))
        .first()
        .expect("Bryn should exist in the graph");

    println!("Found person: {:?}", bryn);

    // Find projects created by a person
    let projects_created_by_bryn = graph
        .walk()
        .vertices_by_id(vec![bryn])
        .edges(Edge::created().outgoing())
        .head()
        .collect::<Vec<_>>();

    println!("Bryn created {} projects", projects_created_by_bryn.len());

    // Find all people followed by Bryn
    let followed_by_bryn = graph
        .walk()
        .vertices_by_id(vec![bryn])
        .edges(Edge::follows().outgoing())
        .head()
        .collect::<Vec<_>>();

    println!("Bryn follows {} people", followed_by_bryn.len());

    // Find all people with "graph" in their biography
    let graph_enthusiasts = graph
        .walk()
        .vertices(Vertex::person_by_biography("graph"))
        .collect::<Vec<_>>();

    println!("Found {} graph enthusiasts", graph_enthusiasts.len());

    // Find people in a specific age range
    let people_in_30s = graph
        .walk()
        .vertices(Vertex::person_by_age_range(30..40))
        .collect::<Vec<_>>();

    println!("Found {} people in their 30s", people_in_30s.len());

Book Organization

This book is organized into several sections:

  • User Guide: How to use the Graph API to work with graph data
  • Implementation Guide: How to implement the Graph API traits for your own graph types
  • Reference: Detailed information about API components and functionality
  • Appendix: Additional resources and reference materials

Whether you're a graph API user or implementing your own graph backend, this book provides comprehensive documentation to help you make the most of the Graph API library.