Search code examples
javagremlingremlin-server

A vertex added using addV() to gremlin-server is not visible when executing a subsequent traversal


I run official gremlin-server image in docker:

docker run -p 8182:8182 tinkerpop/gremlin-server:3.4.10

It starts on port 8182.

Then I execute the following code:

try (RemoteConnection connection = openConnection();
        GraphTraversalSource g = openRemoteTraversalSource(connection)) {

    g.V().addV("Test").property("a", "b").iterate();

    System.out.println(g.V().toList().size());
}

where

private DriverRemoteConnection openConnection() {
    return DriverRemoteConnection.using("localhost", 8182);
}

private GraphTraversalSource openRemoteTraversalSource(RemoteConnection connection) {
    return AnonymousTraversalSource.traversal().withRemote(connection);
}

I have gremlin-driver on classpath:

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.4.10</version>
</dependency>

This code outputs 0. But as I added a vertex using addV() step, I expect to get one result.

I also tried to switch to janusgraph/janusgraph:0.5.3 and get the same result, so I suppose the problem is with my code and not gremlin-server.

But what is missing? Why isn't the added vertex visible?


Solution

  • This line

    g.V().addV("Test").property("a", "b").iterate();
    

    needs to change to

    g.addV("Test").property("a", "b").iterate();