Edges Step

The edges step traverses from vertices to their connecting edges, allowing navigation along relationships in the graph. This step shifts the walker's position from vertices to their adjacent edges, transforming a stream of vertices into a stream of edges.

Edges step diagram showing traversal from a vertex to its outgoing edges

In this diagram:

  • An Input Stream contains vertex A.
  • Vertex A has outgoing edges: A->B (likes) and A->C (created).
  • The .edges(EdgeSearch::scan()) step processes vertex A.
  • The Output Stream contains the edge elements A->B and A->C connected to vertex A.

Syntax

walker.edges(search_criteria)

Where search_criteria is an EdgeSearch object or a predefined search from an index.

Parameters

  • search_criteria: An EdgeSearch object that defines criteria for selecting edges, including:
    • Edge labels
    • Direction (incoming, outgoing, or both)
    • Property values (when supported)

Return Value

Returns a new walker positioned at the edges matching the search criteria.

Examples

Finding All Connected Edges

Get all edges connected to a vertex:

    // Get all edges (both incoming and outgoing) from a vertex
    let all_connected_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(EdgeSearch::scan())
        .collect::<Vec<_>>();

    println!(
        "Found {} total edges connected to Bryn",
        all_connected_edges.len()
    );

Directional Edge Queries

Specify whether you want incoming or outgoing edges:

    // Get only outgoing edges from a vertex
    let outgoing_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(EdgeSearch::scan().outgoing())
        .collect::<Vec<_>>();

    println!("Found {} outgoing edges from Bryn", outgoing_edges.len());

    // Get only incoming edges to a vertex
    let incoming_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(EdgeSearch::scan().incoming())
        .collect::<Vec<_>>();

    println!("Found {} incoming edges to Bryn", incoming_edges.len());

Label-Based Edge Filtering

Filter edges by their label:

    // Get only edges with a specific label
    // Using the label index is more efficient
    let created_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(Edge::created())
        .collect::<Vec<_>>();

    println!("Found {} 'Created' edges for Bryn", created_edges.len());

Combined Filtering

Combine direction and label filtering:

    // Combine direction and label filtering
    let outgoing_follows_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(Edge::follows().outgoing())
        .collect::<Vec<_>>();

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

    // Find incoming follows edges (people who follow Bryn)
    let incoming_follows_edges = graph
        .walk()
        .vertices_by_id([bryn])
        .edges(Edge::follows().incoming())
        .collect::<Vec<_>>();

    println!("{} people follow Bryn", incoming_follows_edges.len());

Best Practices

  • Specify the direction when possible to limit the search space
  • Use label-based indexes to avoid scanning all edges
  • Follow edges step with head() or tail() to continue vertex-based traversals
  • Consider the naming of relationships to match conceptual understanding

Common Use Cases

  • Relationship navigation: Moving from vertices to their connections
  • Filtered relationships: Finding specific types of connections between vertices
  • Direction-specific queries: Finding incoming or outgoing relationships
  • Relationship property examination: Inspecting metadata on connections