Graph
Operations scoped to a single named graph (gharial) on the server.
Instances are obtained through Database::graph() or
Database::createGraph(). The graph name is fixed at
construction time and is interpolated into the
/_api/gharial/{name}/... routes by the helpers below.
The class covers the graph lifecycle, the membership of vertex collections, and the management of edge definitions — i.e. everything that touches the graph's structure on the server. Per-vertex and per-edge CRUD (insert / get / replace / update / remove) lands separately on the GraphVertexCollection and GraphEdgeCollection classes (Lot 7.1b).
Example:
$employs = new EdgeDefinition
(
collection : 'employs' ,
from : [ 'companies' ] ,
to : [ 'people' ] ,
) ;
$graph = $db->createGraph( 'workplaces' , [ $employs ] ) ;
$graph->addVertexCollection( 'departments' ) ;
$graph->addEdgeDefinition
(
new EdgeDefinition( 'reports_to' , [ 'people' ] , [ 'people' ] ) ,
) ;
$graph->drop( dropCollections : true ) ; // also drops vertex/edge collections
Tags
Table of Contents
Constants
- DROP_COLLECTION_PARAM : string = 'dropCollection'
- Query parameter that propagates a drop down to the underlying vertex/edge collections (`/_api/gharial/{graph}/{...}/{name}?dropCollection=true`).
- DROP_COLLECTIONS_PARAM : string = 'dropCollections'
- Query parameter that propagates a drop down to every vertex and edge collection of the graph (`/_api/gharial/{name}?dropCollections=true`).
- EDGE_DEFINITIONS_FIELD : string = 'edgeDefinitions'
- Wire field carrying the list of edge definitions on a graph.
- GRAPH_FIELD : string = 'graph'
- Wire field carrying the graph wrapper in single-graph responses (`POST /_api/gharial`, `GET /_api/gharial/{name}`, `POST|PUT|DELETE .../vertex` / `.../edge`).
- NAME_FIELD : string = 'name'
- Wire field carrying the graph name.
- ORPHAN_COLLECTIONS_FIELD : string = 'orphanCollections'
- Wire field carrying the orphan-collections list of a graph (vertex collections that belong to the graph but are not part of any edge definition).
- COLLECTIONS_FIELD : string = 'collections'
- Wire field carrying the list of vertex collections (gharial-style — graphs-level), on `GET /_api/gharial/{name}/vertex`.
- EDGE_SUB_ROUTE : string = '/edge'
- Sub-route for the edge-collection management endpoint (`/_api/gharial/{graph}/edge`).
- VERTEX_SUB_ROUTE : string = '/vertex'
- Sub-route for the vertex-collection management endpoint (`/_api/gharial/{graph}/vertex`).
Properties
Methods
- __construct() : mixed
- addEdgeDefinition() : array<string, mixed>
- Adds an edge definition to this graph.
- addVertexCollection() : array<string, mixed>
- Adds a vertex collection to this graph (registers a new orphan collection — orphan because it is not yet part of any edge definition).
- create() : array<string, mixed>
- Creates this graph on the server with the given edge definitions.
- drop() : void
- Drops this graph from the server.
- edgeCollection() : GraphEdgeCollection
- Returns a {@see GraphEdgeCollection} handle on the given edge collection inside this graph.
- edgeCollections() : array<int, string>
- Returns the list of edge collection names currently registered on this graph (the names — for the full definitions including `from` / `to`, use {@see edgeDefinitions()}).
- edgeDefinitions() : array<int, EdgeDefinition>
- Returns the list of edge definitions currently registered on this graph, as typed {@see EdgeDefinition} value objects.
- exists() : bool
- Returns true when the graph exists on the server.
- get() : array<string, mixed>
- Returns the raw server-side description of this graph (`GET /_api/gharial/{name}`).
- getName() : string
- Returns the graph name this instance is bound to.
- orphanCollections() : array<int, string>
- Returns the list of orphan vertex collections currently registered on this graph.
- removeEdgeDefinition() : array<string, mixed>
- Removes an edge definition from this graph.
- removeVertexCollection() : array<string, mixed>
- Removes a vertex collection from this graph (must be an orphan collection — vertex collections referenced by an edge definition cannot be removed until the definition itself is removed first).
- replaceEdgeDefinition() : array<string, mixed>
- Replaces an existing edge definition with a new one for the same edge collection.
- vertexCollection() : GraphVertexCollection
- Returns a {@see GraphVertexCollection} handle on the given vertex collection inside this graph.
- vertexCollections() : array<int, string>
- Returns the list of vertex collection names currently registered on this graph (both orphan collections and the ones referenced by an edge definition).
- extractGraph() : array<string, mixed>
- Extracts the `graph` payload from a single-graph response body, falling back to the body itself when the wrapper is absent (defensive — the server always emits the wrapper on success).
- path() : string
- Builds the `/_api/gharial/{name}` path with the graph name URL-encoded.
Constants
DROP_COLLECTION_PARAM
Query parameter that propagates a drop down to the underlying vertex/edge collections (`/_api/gharial/{graph}/{...}/{name}?dropCollection=true`).
public
string
DROP_COLLECTION_PARAM
= 'dropCollection'
DROP_COLLECTIONS_PARAM
Query parameter that propagates a drop down to every vertex and edge collection of the graph (`/_api/gharial/{name}?dropCollections=true`).
public
string
DROP_COLLECTIONS_PARAM
= 'dropCollections'
EDGE_DEFINITIONS_FIELD
Wire field carrying the list of edge definitions on a graph.
public
string
EDGE_DEFINITIONS_FIELD
= 'edgeDefinitions'
GRAPH_FIELD
Wire field carrying the graph wrapper in single-graph responses (`POST /_api/gharial`, `GET /_api/gharial/{name}`, `POST|PUT|DELETE .../vertex` / `.../edge`).
public
string
GRAPH_FIELD
= 'graph'
NAME_FIELD
Wire field carrying the graph name.
public
string
NAME_FIELD
= 'name'
ORPHAN_COLLECTIONS_FIELD
Wire field carrying the orphan-collections list of a graph (vertex collections that belong to the graph but are not part of any edge definition).
public
string
ORPHAN_COLLECTIONS_FIELD
= 'orphanCollections'
COLLECTIONS_FIELD
Wire field carrying the list of vertex collections (gharial-style — graphs-level), on `GET /_api/gharial/{name}/vertex`.
private
string
COLLECTIONS_FIELD
= 'collections'
EDGE_SUB_ROUTE
Sub-route for the edge-collection management endpoint (`/_api/gharial/{graph}/edge`).
private
string
EDGE_SUB_ROUTE
= '/edge'
VERTEX_SUB_ROUTE
Sub-route for the vertex-collection management endpoint (`/_api/gharial/{graph}/vertex`).
private
string
VERTEX_SUB_ROUTE
= '/vertex'
Properties
$database
public
Database
$database
$name
public
string
$name
Methods
__construct()
public
__construct(Database $database, string $name) : mixed
Parameters
- $database : Database
-
Parent database (provides the shared HTTP transport).
- $name : string
-
Name of the target graph on the server.
addEdgeDefinition()
Adds an edge definition to this graph.
public
addEdgeDefinition(EdgeDefinition $definition) : array<string, mixed>
Wraps POST /_api/gharial/{name}/edge. The server validates
that the edge collection is not already part of another graph
with a conflicting definition and rejects on
1928 (GRAPH_EDGE_COLLECTION_USED).
Parameters
- $definition : EdgeDefinition
-
The edge definition to register.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
addVertexCollection()
Adds a vertex collection to this graph (registers a new orphan collection — orphan because it is not yet part of any edge definition).
public
addVertexCollection(string $collection) : array<string, mixed>
Wraps POST /_api/gharial/{name}/vertex. The server creates the
collection if it does not exist yet.
Parameters
- $collection : string
-
Name of the vertex collection to register.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
create()
Creates this graph on the server with the given edge definitions.
public
create([array<int, EdgeDefinition> $edgeDefinitions = [] ][, array<string, mixed> $options = [] ]) : array<string, mixed>
Wraps POST /_api/gharial. The graph name is taken from
$name. Recognised options include orphanCollections
(an array of vertex collection names not yet part of any edge
definition), numberOfShards, replicationFactor,
writeConcern, waitForSync, isSmart, smartGraphAttribute,
isDisjoint, satellites — the last four are Enterprise-only
(silently ignored on Community editions).
Parameters
- $edgeDefinitions : array<int, EdgeDefinition> = []
-
Edge definitions to register on creation (may be empty for a vertex-only / orphan graph).
- $options : array<string, mixed> = []
-
Extra creation options.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
drop()
Drops this graph from the server.
public
drop([bool $dropCollections = false ]) : void
Wraps DELETE /_api/gharial/{name}. When $dropCollections is
true, every vertex and edge collection that belongs to this
graph (and is not shared with another graph) is also dropped —
use with care, data is lost. When false (default), the
collections are kept as orphans.
Parameters
- $dropCollections : bool = false
-
Whether to drop the underlying vertex/edge collections.
Tags
edgeCollection()
Returns a {@see GraphEdgeCollection} handle on the given edge collection inside this graph.
public
edgeCollection(string $name) : GraphEdgeCollection
No HTTP call is made — the handle is purely client-side.
Routes its CRUD operations through /_api/gharial/{graph}/edge/{collection}/...
so the server enforces the graph's edge-definition constraints
on _from / _to.
Parameters
- $name : string
-
Name of the edge collection.
Return values
GraphEdgeCollectionedgeCollections()
Returns the list of edge collection names currently registered on this graph (the names — for the full definitions including `from` / `to`, use {@see edgeDefinitions()}).
public
edgeCollections() : array<int, string>
Wraps GET /_api/gharial/{name}/edge.
Tags
Return values
array<int, string>edgeDefinitions()
Returns the list of edge definitions currently registered on this graph, as typed {@see EdgeDefinition} value objects.
public
edgeDefinitions() : array<int, EdgeDefinition>
Reads from GET /_api/gharial/{name} (the same endpoint as
get()), so it costs a single round trip.
Tags
Return values
array<int, EdgeDefinition>exists()
Returns true when the graph exists on the server.
public
exists() : bool
Treats a 404 as a clean "missing" and rethrows everything else.
Tags
Return values
boolget()
Returns the raw server-side description of this graph (`GET /_api/gharial/{name}`).
public
get() : array<string, mixed>
Carries _key / _id / _rev / name / edgeDefinitions /
orphanCollections, and Enterprise-only numberOfShards /
replicationFactor / writeConcern / isSmart / … on cluster
deployments.
Tags
Return values
array<string, mixed>getName()
Returns the graph name this instance is bound to.
public
getName() : string
Return values
stringorphanCollections()
Returns the list of orphan vertex collections currently registered on this graph.
public
orphanCollections() : array<int, string>
Tags
Return values
array<int, string>removeEdgeDefinition()
Removes an edge definition from this graph.
public
removeEdgeDefinition(string $collection[, bool $dropCollection = false ]) : array<string, mixed>
Wraps DELETE /_api/gharial/{name}/edge/{collection}. When
$dropCollection is true, the edge collection itself is also
dropped from the database (data is lost).
Parameters
- $collection : string
-
Name of the edge collection whose definition is being removed.
- $dropCollection : bool = false
-
Also drop the underlying edge collection.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
removeVertexCollection()
Removes a vertex collection from this graph (must be an orphan collection — vertex collections referenced by an edge definition cannot be removed until the definition itself is removed first).
public
removeVertexCollection(string $collection[, bool $dropCollection = false ]) : array<string, mixed>
Wraps DELETE /_api/gharial/{name}/vertex/{collection}. When
$dropCollection is true, the underlying vertex collection is
also dropped from the database.
Parameters
- $collection : string
-
Name of the vertex collection.
- $dropCollection : bool = false
-
Also drop the underlying vertex collection.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
replaceEdgeDefinition()
Replaces an existing edge definition with a new one for the same edge collection.
public
replaceEdgeDefinition(EdgeDefinition $definition) : array<string, mixed>
Wraps PUT /_api/gharial/{name}/edge/{collection}. Useful to
widen or narrow the allowed from / to vertex collections
without recreating the graph.
Parameters
- $definition : EdgeDefinition
-
New definition. The
collectionfield selects the target.
Tags
Return values
array<string, mixed> —Raw graph payload as returned by the server.
vertexCollection()
Returns a {@see GraphVertexCollection} handle on the given vertex collection inside this graph.
public
vertexCollection(string $name) : GraphVertexCollection
No HTTP call is made — the handle is purely client-side.
Routes its CRUD operations through /_api/gharial/{graph}/vertex/{collection}/...
so the server enforces the graph's referential constraints
(e.g. preventing edge collections from referencing a vertex
that does not exist).
Parameters
- $name : string
-
Name of the vertex collection.
Return values
GraphVertexCollectionvertexCollections()
Returns the list of vertex collection names currently registered on this graph (both orphan collections and the ones referenced by an edge definition).
public
vertexCollections() : array<int, string>
Wraps GET /_api/gharial/{name}/vertex.
Tags
Return values
array<int, string>extractGraph()
Extracts the `graph` payload from a single-graph response body, falling back to the body itself when the wrapper is absent (defensive — the server always emits the wrapper on success).
private
extractGraph(mixed $body) : array<string, mixed>
Parameters
- $body : mixed
-
Decoded response body.
Return values
array<string, mixed>path()
Builds the `/_api/gharial/{name}` path with the graph name URL-encoded.
private
path() : string