Graph objects are constructed with a schema type map.
let jseg = require('jseg');
let [builder, types] = jseg.newSchema();
... // Build-up and finalize schema.
let graph = new jseg.Graph(types);
Gets an entity by "local id".
graph.get(lid, [options])
Entities are copies of data from the graph and so are safe to mutate.
Relationships are returned as nested objects with a lid
key. Additional
information about related entities can be acquired via additional queries
or recursively with the depth
option.
Null field values and empty collections are included.
Returns null if the object does not exist.
graph.lookup('entity123');
graph.lookup(type, fieldName, value, [options])
Behaves like get
, but works on any field with of type Key
.
graph.lookup('User', 'username', 'brandonbloom');
depth
: Defines maximum number of references to follow when building the
hierarchical query result. Default is 1
. Specify 0
for unlimited.
Cyclic references are never followed and are returned as an object with
only a lid
key like when exceeding max depth.
json
: Set to true
to have scalar values converted to JSON. Useful for
serializing the output of a query.
graph.put(entity)
Puts a whole tree of related objects. Properties are merged in to existing
objects with matching lid
fields. Relationship arrays are set-unioned.
Fields set to null are deleted from entities.
graph.destroy(lid)
Removes an object from the graph by lid. Recursively destroys related objects if cascading is specified in the schema.
graph.remove(fromLid, fieldName, toLid)
Removes a related object from a set of references.
Treats references of cardinality one
as a set with a max size of one.