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

EdgeRelationID Unmarshal Issue #14

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

After adding two vertices to a local Gremlin Server graph (3.4.6) I attempt to create an edge between them by first checking for existing edges:

 _, err = vertex1.QueryOutEdges(client)

This results in the following error when the edge exist:

2020/02/28 19:23:33 Error while querying for outer edges {"type":"UNMARSHAL_ERROR"},{"function":"UnmarshalEdgeList"},{"rawBytes":"{"@type":"g:List","@value":[{"@type":"g:Edge","@value":{"id":{"@type":"g:Int64","@value":291},"inV":{"@type":"g:Int64","@value":108},"inVLabel":"article:c","label":"has content","outV":{"@type":"g:Int64","@value":254},"outVLabel":"article:m"}}]}"},{"error":"json: cannot unmarshal number into Go struct field EdgeID.@value.id.@value of type model.EdgeRelationID"}

Anything I'm doing wrong in config or code, or is this a bug with the types?

ghost commented 4 years ago

So it seems like the object returned from Gremlin Server is the issue.

To fix it I changed https://github.com/northwesternmutual/grammes/blob/master/model/edgeid.go#L27 to:

Value int64          `json:"@value"`

Thus, it is necessary to update https://github.com/northwesternmutual/grammes/blob/master/model/edge.go#L46 as well:

func (e *Edge) ID() int64 {
    return e.Value.ID.Value
}

I haven't been doing much with Gremlin lately, so this may be a configuration or scheme thing, but at least this works with the current Gremlin Server out of the box.