Skip to the content.

Manipulating edges

graph.edgeCollection

graph.edgeCollection(collectionName): GraphEdgeCollection

Returns a new GraphEdgeCollection instance with the given name bound to this graph.

Arguments

Examples

const db = new Database();
// assuming the collections "edges" and "vertices" exist
const graph = db.graph("some-graph");
const collection = graph.edgeCollection("edges");
assert.equal(collection.name, "edges");
// collection is a GraphEdgeCollection

graph.addEdgeDefinition

async graph.addEdgeDefinition(definition): Object

Adds the given edge definition definition to the graph.

Arguments

Examples

const db = new Database();
// assuming the collections "edges" and "vertices" exist
const graph = db.graph("some-graph");
await graph.addEdgeDefinition({
  collection: "edges",
  from: ["vertices"],
  to: ["vertices"],
});
// the edge definition has been added to the graph

graph.replaceEdgeDefinition

async graph.replaceEdgeDefinition(collectionName, definition): Object

Replaces the edge definition for the edge collection named collectionName with the given definition.

Arguments

Examples

const db = new Database();
// assuming the collections "edges", "vertices" and "more-vertices" exist
const graph = db.graph("some-graph");
await graph.replaceEdgeDefinition("edges", {
  collection: "edges",
  from: ["vertices"],
  to: ["more-vertices"],
});
// the edge definition has been modified

graph.removeEdgeDefinition

async graph.removeEdgeDefinition(definitionName, [dropCollection]): Object

Removes the edge definition with the given definitionName form the graph.

Arguments

Examples

const db = new Database();
const graph = db.graph("some-graph");

await graph.removeEdgeDefinition("edges");
// the edge definition has been removed

// -- or --

await graph.removeEdgeDefinition("edges", true);
// the edge definition has been removed
// and the edge collection "edges" has been dropped
// this may have been a bad idea

graph.traversal

async graph.traversal(startVertex, opts): Object

Performs a traversal starting from the given startVertex and following edges contained in any of the edge collections of this graph.

Arguments

Examples

const db = new Database();
const graph = db.graph("some-graph");
const collection = graph.edgeCollection("edges");
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",
  visitor: "result.vertices.push(vertex._key);",
  init: "result.vertices = [];",
});
assert.deepEqual(result.vertices, ["a", "b", "c", "d"]);