gsql/ Vertex & Edge Methods
Last Updated: October 20, 2018

Built-in functions for manipulating graph elements and accessing metadata.

Vertex & Edge Methods

GSQL provides a rich set of built-in methods to interact with vertices and edges directly.

1. Core Vertex Methods

Invoke these on a vertex variable or alias using the dot (.) operator.

MethodDescriptionReturn Type
.outdegree()Returns the count of outgoing edges.INT
.getAttr()Dynamically retrieves an attribute value.BaseType
.setAttr()Dynamically updates an attribute value.void
.neighbors()Returns a collection of immediate neighbors.BagAccum<VERTEX>

Performance Tip: outdegree()

outdegree() is extremely fast because it reads from metadata. However, in high-concurrency write environments, it may be slightly delayed. For exact real-time counts, use a manual traversal.

2. Core Edge Methods

Invoke these on an edge alias inside a SELECT statement.

  • .getAttr(name, type): Retrieves an edge attribute.
  • .setAttr(name, value): Updates an edge attribute.
  • .isDirected(): Returns true if the edge is directed.

3. ID & Conversion Functions

These functions handle the mapping between external (user-facing) IDs and internal (engine) IDs.

  • getvid(v): Returns the internal numeric ID of a vertex. Useful for algorithms like Community Detection where speed is critical.
  • to_vertex(id, type): Converts a string ID and type into a VERTEX object.
  • to_vertex_set(id_collection, type): Converts a collection of string IDs into a SET<VERTEX>.

[!CAUTION] Performance Warning: to_vertex and to_vertex_set are relatively expensive operations. Do not use them inside ACCUM or POST-ACCUM blocks, as they will execute for every edge/vertex, severely impacting performance. Instead, resolve IDs at the start of the query.

4. Metadata Functions

  • elementId(v/e): Returns a persistent internal string ID.
  • .type: Returns the type name of the vertex or edge as a string.
  • .neighbors().filter(): Allows inline filtering of neighbor collections without a full SELECT statement.