Represents a graph in a Database.

Hierarchy

  • Graph

Accessors

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

    Returns string

Methods

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    await graph.addVertexCollection("more-vertices");
    // The collection "more-vertices" has been added to the graph
    const extra = db.collection("extra-vertices");
    await graph.addVertexCollection(extra);
    // The collection "extra-vertices" has been added to the graph

    Parameters

    Returns Promise<GraphInfo>

  • 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>

  • 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

    • dropCollections: boolean = false

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

    Returns Promise<boolean>

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    const graphEdgeCollection = graph.edgeCollection("edges");
    // Access the underlying EdgeCollection API:
    const edgeCollection = graphEdgeCollection.collection;

    Type Parameters

    • T extends Record<string, any> = any

      Type to use for document data. Defaults to any.

    Parameters

    Returns GraphEdgeCollection<T>

  • Fetches all edge collections of this graph from the database and returns an array of GraphEdgeCollection instances.

    See also listEdgeCollections.

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    const graphEdgeCollections = await graph.edgeCollections();
    for (const collection of graphEdgeCollection) {
    console.log(collection.name);
    // "edges"
    }

    Returns Promise<GraphEdgeCollection<any>[]>

  • 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>

  • 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>

  • Fetches all edge collections of this graph from the database and returns an array of their names.

    See also edgeCollections.

    Example

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

    Returns Promise<string[]>

  • Fetches all vertex collections of this graph from the database and returns an array of their names.

    See also vertexCollections.

    Example

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

    Returns Promise<string[]>

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    await graph.removeEdgeDefinition("edges");
    // The edge definition for "edges" has been replaced

    Parameters

    • collection: string | ArangoCollection

      Edge collection for which to remove the definition.

    • dropCollection: boolean = false

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

    Returns Promise<GraphInfo>

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    await graph.removeVertexCollection("start-vertices");
    // The collection "start-vertices" is no longer part of the graph.

    Parameters

    • collection: string | ArangoCollection

      Collection to remove from the graph.

    • dropCollection: boolean = false

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

    Returns Promise<GraphInfo>

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    await graph.replaceEdgeDefinition({
    collection: "edges",
    from: ["start-vertices"],
    to: ["other-vertices"],
    });
    // The edge definition for "edges" has been replaced

    Parameters

    Returns Promise<GraphInfo>

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

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    await graph.replaceEdgeDefinition("edges", {
    collection: "edges",
    from: ["start-vertices"],
    to: ["other-vertices"],
    });
    // The edge definition for "edges" has been replaced

    Parameters

    Returns Promise<GraphInfo>

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

    See also 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 startVertex = "vertices/a";
    const cursor = await db.query(aql`
    FOR vertex IN OUTBOUND ${startVertex} GRAPH ${graph}
    RETURN vertex._key
    `);
    const result = await cursor.all();
    console.log(result); // ["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>

  • Fetches all vertex collections of this graph from the database and returns an array of GraphVertexCollection instances.

    See also listVertexCollections.

    Example

    const db = new Database();
    const graph = db.graph("some-graph");
    const info = await graph.create([
    {
    collection: "edges",
    from: ["start-vertices"],
    to: ["end-vertices"],
    },
    ]);
    const vertexCollections = await graph.vertexCollections();
    for (const vertexCollection of vertexCollections) {
    console.log(vertexCollection.name);
    // "start-vertices"
    // "end-vertices"
    }

    Returns Promise<GraphVertexCollection<any>[]>

Generated using TypeDoc