Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Graph

Represents a graph in a Database.

Hierarchy

  • Graph

Index

Accessors

name

  • get name(): string
  • Name of the graph.

    Returns string

Methods

addEdgeDefinition

  • Adds an edge definition to this graph.

    Parameters

    Returns Promise<GraphInfo>

addVertexCollection

  • Adds the given collection to this graph as a vertex collection.

    Parameters

    Returns Promise<GraphInfo>

create

  • Creates a graph with the given edgeDefinitions and options for this graph's name.

    example
    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
      {
        collection: "edges",
        from: ["start-vertices"],
        to: ["end-vertices"],
      },
    ]);
    // graph now exists

    Parameters

    Returns Promise<GraphInfo>

drop

  • drop(dropCollections?: boolean): Promise<boolean>
  • Deletes the graph from the database.

    example
    const db = new Database();
    const graph = db.graph("some-graph");
    await graph.drop();
    // the graph "some-graph" no longer exists

    Parameters

    • Default value dropCollections: boolean = false

      If set to true, the collections associated with the graph will also be deleted.

    Returns Promise<boolean>

edgeCollection

  • Returns a GraphEdgeCollection instance for the given collection name representing the collection in this graph.

    Type parameters

    • T: object

      Type to use for document data. Defaults to any.

    Parameters

    Returns GraphEdgeCollection<T>

edgeCollections

exists

  • exists(): Promise<boolean>
  • Checks whether the graph exists.

    example
    const db = new Database();
    const graph = db.graph("some-graph");
    const result = await graph.exists();
    // result indicates whether the graph exists

    Returns Promise<boolean>

get

  • Retrieves general information about the graph.

    example
    const db = new Database();
    const graph = db.graph("some-graph");
    const data = await graph.get();
    // data contains general information about the graph

    Returns Promise<GraphInfo>

listEdgeCollections

  • listEdgeCollections(): Promise<string[]>
  • Fetches all edge collections of this graph from the database and returns an array of their names.

    See also Graph.edgeCollections.

    Returns Promise<string[]>

listVertexCollections

  • listVertexCollections(): Promise<string[]>
  • Fetches all vertex collections of this graph from the database and returns an array of their names.

    See also Graph.vertexCollections.

    Returns Promise<string[]>

removeEdgeDefinition

  • Removes the edge definition for the given edge collection from this graph.

    Parameters

    • collection: string | ArangoCollection

      Edge collection for which to remove the definition.

    • Default value dropCollection: boolean = false

      If set to true, the collection will also be deleted from the database.

    Returns Promise<GraphInfo>

removeVertexCollection

  • Removes the given collection from this graph as a vertex collection.

    Parameters

    • collection: string | ArangoCollection

      Collection to remove from the graph.

    • Default value dropCollection: boolean = false

      If set to true, the collection will also be deleted from the database.

    Returns Promise<GraphInfo>

replaceEdgeDefinition

  • Replaces an edge definition in this graph. The existing edge definition for the given edge collection will be overwritten.

    Parameters

    Returns Promise<GraphInfo>

  • Replaces an edge definition in this graph. The existing edge definition for the given edge collection will be overwritten.

    Parameters

    Returns Promise<GraphInfo>

traversal

  • Performs a traversal starting from the given startVertex and following edges contained in this graph.

    See also EdgeCollection.traversal.

    deprecated

    Simple Queries have been deprecated in ArangoDB 3.4 and can be replaced with AQL queries.

    example
    const db = new Database();
    const graph = db.graph("my-graph");
    const collection = graph.edgeCollection("edges").collection;
    await collection.import([
      ["_key", "_from", "_to"],
      ["x", "vertices/a", "vertices/b"],
      ["y", "vertices/b", "vertices/c"],
      ["z", "vertices/c", "vertices/d"],
    ]);
    const result = await graph.traversal("vertices/a", {
      direction: "outbound",
      init: "result.vertices = [];",
      visitor: "result.vertices.push(vertex._key);",
    });
    console.log(result.vertices); // ["a", "b", "c", "d"]

    Parameters

    • startVertex: string

      Document _id of a vertex in this graph.

    • Optional options: TraversalOptions

      Options for performing the traversal.

    Returns Promise<any>

vertexCollection

  • Returns a GraphVertexCollection instance for the given collection name representing the collection in this graph.

    Type parameters

    • T: object

      Type to use for document data. Defaults to any.

    Parameters

    Returns GraphVertexCollection<T>

vertexCollections

Generated using TypeDoc