addEdge

How to specify an edge.

Synopsis

vertex1.
addEdge('edgeLabel', vertex2, [T.id, 'edge_id'], ['key', 'value'] [,...])

Description

Edge data is inserted using addEdge. A previously created edge label must be specified. An edge_id may be specified, to upsert data for a multiple cardinality edge to prevent creation of a new edge. Property key-value pairs may be optionally specified. Specification of the vertices must exist to add an edge.

Examples

For the examples below, the vertices are already specified and created:
johnDoe = graph.addVertex(label, 'person','person_id', UUID.fromString('46ad98ac-f5c9-4411-815a-f81b3b667921'), 'name', 'John DOE')
beefBourguignon = g.V().has('recipe', 'recipe_id',2001).tryNext().orElseGet {graph.addVertex(label, 'recipe', 'recipe_id', 2001, 'name', 'Beef Bourguignon')}
juliaChild = graph.addVertex(label, 'person', 'person_id', UUID.fromString('e7cd5752-bc0d-4157-a80f-7523add8dbcd'), 'name', 'Julia CHILD')
Create an edge with an edge label reviewed between the vertices johnDoe and beefBourguignon with the properties time, year, stars, and comment:
johnDoe.addEdge('reviewed', beefBourguignon, 'time', '00:00:00.00', 'year', '2014-01-01', 'stars', 5, 'comment', 'Pretty tasty!')
Update an edge with an edge label created between the vertices juliaChild and beefBourguignon, specifying the edge with an edge id of e3c827f1-0bd0-11ea-9381-5f09530fbca8, and a property create_date of 2017-08-22:
juliaChild.addEdge('created', beefBourguignon, T.id, java.util.UUID.fromString('e3c827f1-0bd0-11ea-9381-5f09530fbca8'), 'create_date', '2017-08-22')
Note that a conversion function must be used to convert a string to the UUID. T.id is a literal that must be included in the statement.