northwesternmutual / grammes

A Go package built to communicate with Apache TinkerPop™ Graph computing framework using Gremlin; a graph traversal language used by graph databases such as JanusGraph®, MS Cosmos DB, AWS Neptune, and DataStax® Enterprise Graph.
Apache License 2.0
125 stars 45 forks source link

add edge error #20

Open UncleBig opened 4 years ago

UncleBig commented 4 years ago

Hi, I refer to the example to add the edge operation, but the following error is returned,Could you please check where I made the mistake

{"error": "{\"type\":\"QUERY_ERROR\"},{\"function\":\"AddEdge\"},{\"query\":\"g.V().hasId(map[@type:g:Int64 @value:16432]).addE(\"friendsWith\").to(V().hasId(map[@type:g:Int64 @value:12408]))\"},{\"error\":\"{\"type\":\"NETWORK_ERROR\"},{\"status code\":\"597\"},{\"error\":\"SCRIPT EVALUATION ERROR\"},{\"original error\":\"startup failed:\nScript19.groovy: 1: unexpected token: : @ line 1, column 22.\n g.V().hasId(map[@type:g:Int64 @value:16432]).addE(\"friendsWith\").to(V().hasId(map[@type:g:Int64 @value:12408]))\n

func main() {
flag.StringVar(&addr, "h", "", "Connection IP")
flag.Parse()

logger = exampleutil.SetupLogger()
defer logger.Sync()

if addr == "" {
    addr="ws://127.0.0.1:8182"
}

// Create a new Grammes client with a standard websocket.
client, err := grammes.DialWithWebSocket(addr)
if err != nil {
    logger.Fatal("Couldn't create client", zap.Error(err))
}

// Drop all vertices on the graph currently.
client.DropAll()

// Drop the testing vertices when finished.
defer client.DropAll()

// Create a new graph traversal
g := grammes.Traversal()

// Add a vertex with label person and properties
vertex, err := client.AddVertexByQuery(g.AddV("person").Property("name", "damien"))
if err != nil {
    logger.Fatal("Couldn't add vertex", zap.Error(err))
}

// Print out the new vertex struct and its properties.
logger.Info("Added vertex",
    zap.Any("name", vertex.PropertyValue("name", 0)),
)
vertex2, err := client.AddVertexByQuery(g.AddV("person").Property("name", "test"))
if err != nil {
    logger.Fatal("Couldn't add vertex", zap.Error(err))
}
logger.Info("Added vertex",
    zap.Any("name", vertex2.PropertyValue("name", 0)),
)
// Count the vertices on the graph.
count, err := client.VertexCount()
if err != nil {
    logger.Fatal("Couldn't count vertices", zap.Error(err))
}

// Print out the number of vertices on the graph.
// This should be 1.
logger.Info("Counted Vertices", zap.Int64("count", count))

vertices, err := client.VerticesByQuery(g.V().HasLabel("person"))
if err != nil {
    logger.Fatal("Couldn't gather vertices", zap.Error(err))
}

// Print out all the received vertices.
for _, vertex := range vertices {
    logger.Info("gathered vertex",
        zap.String("label", vertex.Label()),
        zap.Any("id", vertex.ID()),
    )
}

// Use the traversal to gather all IDs from the graph.
ids, err := client.VertexIDsByQuery(g.V().ID())
if err != nil {
    logger.Fatal("Couldn't gather all IDs", zap.Error(err))
}

// Print out all the received vertex IDs.
for _, id := range ids {
    logger.Info("vertex id", zap.Any("value", id))
}

_,err=vertex.AddEdge(client, "friendsWith", vertex2.ID())

if err != nil {
    logger.Fatal("AddEdge error", zap.Error(err))
    return
}

// Get the edges based on vertex1's out edges.
edges, err := vertex.QueryOutEdges(client)
if err != nil {
    logger.Fatal("Error while querying for outer edges", zap.Error(err))
}

printEdges(client, edges)

}`

damienfamed75 commented 4 years ago

What database are you using for this example

UncleBig commented 4 years ago

I use the janusgraph docker run --name janusgraph-default -p 8182:8182 janusgraph/janusgraph:latest

arjantop-cai commented 4 years ago

@UncleBig The current solution is the same as here: https://github.com/northwesternmutual/grammes/issues/18

Downgrade to v1.1.2