Creating vertices and edges in DataStax Studio

Steps to add Gremlin code to a notebook to create a simple two vertex, one edge graph.

Prerequisites

Add Gremlin code to a notebook to create a simple two vertex, one edge graph.

Procedure

  1. If necessary, start DataStax Studio and open the notebook you previously created.
When you create a notebook, an empty graph instance is created and named after the value in the graph name field in the notebook's connection. A local variable, g, is defined automatically and bound to that graph.
  1. Add a cell to the notebook.
  2. Ensure that Gremlin is selected in the menu for the notebook cell editor mode:
  3. Add the code to the cell to create some vertices and edges for the graph.
    schema.config().option('graph.schema_mode').set('Development')
    
    Vertex firstVertex = graph.addVertex(label, 'user', 'id', 1, 'name', 'Jo Dowe', 'role', 'customer')
    Vertex secondVertex = graph.addVertex(label,'product', 'id', 2, 'name', 'fountain pen')
    firstVertex.addEdge('bought', secondVertex)
    g.V()
    

    These lines of code, put DSE Graph in development mode, create two vertices, and connect them with a single edge.

  4. Select Run Cell to execute the code.
  5. Select Graph in Display toolbar. (By default, the Table view is displayed.)

  6. Hover your mouse over a vertex to display its properties.

What's next

See the DSE Graph documentation.