Skip to content

Commit a0883ed

Browse files
Merge pull request #16 from beyondnetworks/master
Updates to support Amazon Neptune
2 parents e76d18e + 16495be commit a0883ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+162
-304
lines changed

examples/add-vertex-by-struct/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070

7171
// Print out the resulting vertex and its values.
7272
logger.Info("Vertex", zap.String("label", vertex.Label()))
73-
logger.Info("Vertex", zap.Int64("ID", vertex.ID()))
73+
logger.Info("Vertex", zap.Any("ID", vertex.ID()))
7474

7575
for k, v := range vertex.PropertyMap() {
7676
logger.Info("Property", zap.Any(k, v[0].GetValue()))

examples/all-vertices/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
for _, vertex := range vertices {
7474
logger.Info("gathered vertex",
7575
zap.String("label", vertex.Label()),
76-
zap.Int64("id", vertex.ID()),
76+
zap.Any("id", vertex.ID()),
7777
)
7878
}
7979
}

examples/drop-vertex-by-id/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of dropping vertices using only their IDs using the `DropVertexByID`
44

55
## Description
66

7-
**drop-vertex-by-id** demonstrates how to drop specific vertices on the graph using their IDs. Specifically this examples shows how to drop the vertices using the `DropVertexByID` function in the Grammes client which takes in an `int64` for the ID of the vertex.
7+
**drop-vertex-by-id** demonstrates how to drop specific vertices on the graph using their IDs. Specifically this examples shows how to drop the vertices using the `DropVertexByID` function in the Grammes client which takes in an object for the ID of the vertex.
88

99
## Prerequisites
1010

examples/id-by-label/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDs` function.
44

55
## Description
66

7-
**id-by-label** demonstrates how to get vertex IDs using a label. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and returns a `[]int64` and `error`. *(This function has multiple purposes and is also shown in `id-by-property`)*
7+
**id-by-label** demonstrates how to get vertex IDs using a label. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and returns a `[]interface{}` and `error`. *(This function has multiple purposes and is also shown in `id-by-property`)*
88

99
## Prerequisites
1010

examples/id-by-label/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ func main() {
7373
// Print out all the received vertex IDs.
7474
// This should only print out one ID.
7575
for _, id := range ids {
76-
logger.Info("vertex id", zap.Int64("value", id))
76+
logger.Info("vertex id", zap.Any("value", id))
7777
}
7878
}

examples/id-by-property/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDs` function.
44

55
## Description
66

7-
**id-by-property** demonstrates how to get vertex IDs using a label and vertex properties. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and `...interface{}` for properties. Then returns a `[]int64` and `error`. *(This function has multiple purposes and is also shown in `id-by-label`)*
7+
**id-by-property** demonstrates how to get vertex IDs using a label and vertex properties. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and `...interface{}` for properties. Then returns a `[]interface{}` and `error`. *(This function has multiple purposes and is also shown in `id-by-label`)*
88

99
## Prerequisites
1010

examples/id-by-property/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ func main() {
7474
// Print out all the received vertex IDs.
7575
// This should only print out one ID.
7676
for _, id := range ids {
77-
logger.Info("vertex id", zap.Int64("value", id))
77+
logger.Info("vertex id", zap.Any("value", id))
7878
}
7979
}

examples/id-by-query/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDsByQuery` function.
44

55
## Description
66

7-
**id-by-query** demonstrates how to get vertex IDs using a `Query` object. Specifically this examples shows how to by using the `VertexIDsByQuery` function which takes a `Query` object that's meant to identify one or more vertices then returns a `[]int64` and `error`.
7+
**id-by-query** demonstrates how to get vertex IDs using a `Query` object. Specifically this examples shows how to by using the `VertexIDsByQuery` function which takes a `Query` object that's meant to identify one or more vertices then returns a `[]interface{}` and `error`.
88

99
## Prerequisites
1010

examples/id-by-query/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ func main() {
7575

7676
// Print out all the received vertex IDs.
7777
for _, id := range ids {
78-
logger.Info("vertex id", zap.Int64("value", id))
78+
logger.Info("vertex id", zap.Any("value", id))
7979
}
8080
}

examples/id-by-string/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDsByString` function.
44

55
## Description
66

7-
**id-by-query** demonstrates how to get vertex IDs using a `string` query. Specifically this examples shows how to by using the `VertexIDsByString` function which takes a `string` query that's meant to identify one or more vertices then returns a `[]int64` and `error`.
7+
**id-by-query** demonstrates how to get vertex IDs using a `string` query. Specifically this examples shows how to by using the `VertexIDsByString` function which takes a `string` query that's meant to identify one or more vertices then returns a `[]interface{}` and `error`.
88

99
## Prerequisites
1010

examples/id-by-string/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ func main() {
7272

7373
// Print out all the received vertex IDs.
7474
for _, id := range ids {
75-
logger.Info("vertex id", zap.Int64("value", id))
75+
logger.Info("vertex id", zap.Any("value", id))
7676
}
7777
}

examples/vertex-by-id/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The basics of getting vertices using the `VertexByID` function from a Grammes cl
44

55
## Description
66

7-
**vertex-by-id** demonstrates how to receive a vertex on the graph using a Grammes client. Specifically this examples shows how to by using the `VertexByID` function which takes in an `int64` as the ID. Then returns a slice of `Vertex` and `error`.
7+
**vertex-by-id** demonstrates how to receive a vertex on the graph using a Grammes client. Specifically this examples shows how to by using the `VertexByID` function which takes in an object as the ID. Then returns a slice of `Vertex` and `error`.
88

99
## Prerequisites
1010

examples/vertex-by-id/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ func main() {
7878
// Print out the received vertex.
7979
logger.Info("gathered vertex",
8080
zap.String("label", vertex.Label()),
81-
zap.Int64("id", vertex.ID()),
81+
zap.Any("id", vertex.ID()),
8282
)
8383
}

examples/vertex-edge-example/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,20 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) {
116116
// its ID, label, and its properties.
117117

118118
logger.Info("Edge",
119-
zap.String("ID", edges[0].ID()),
119+
zap.Any("ID", edges[0].ID()),
120120
zap.String("Label", edges[0].Label()),
121121
zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")),
122122
zap.Any("driveDist", edges[0].PropertyValue("driveDist")),
123123
)
124124

125125
logger.Info("OutVertex",
126-
zap.Int64("ID", edges[0].OutVertexID()),
126+
zap.Any("ID", edges[0].OutVertexID()),
127127
zap.String("Label", edges[0].OutVertexLabel()),
128128
zap.Any("Name", v1.PropertyValue("name", 0)),
129129
)
130130

131131
logger.Info("InVertex",
132-
zap.Int64("ID", edges[0].InVertexID()),
132+
zap.Any("ID", edges[0].InVertexID()),
133133
zap.String("Label", edges[0].InVertexLabel()),
134134
zap.Any("Name", v2.PropertyValue("name", 0)),
135135
)

examples/vertices-by-label/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func main() {
7474
for _, vertex := range vertices {
7575
logger.Info("gathered vertex",
7676
zap.String("label", vertex.Label()),
77-
zap.Int64("id", vertex.ID()),
77+
zap.Any("id", vertex.ID()),
7878
)
7979
}
8080
}

examples/vertices-by-property/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func main() {
7474
for _, vertex := range vertices {
7575
logger.Info("gathered vertex",
7676
zap.String("label", vertex.Label()),
77-
zap.Int64("id", vertex.ID()),
77+
zap.Any("id", vertex.ID()),
7878
zap.Any("name", vertex.PropertyValue("name", 0)),
7979
)
8080
}

examples/vertices-by-query/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func main() {
7676
for _, vertex := range vertices {
7777
logger.Info("gathered vertex",
7878
zap.String("label", vertex.Label()),
79-
zap.Int64("id", vertex.ID()),
79+
zap.Any("id", vertex.ID()),
8080
)
8181
}
8282
}

examples/vertices-by-string/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
for _, vertex := range vertices {
7474
logger.Info("gathered vertex",
7575
zap.String("label", vertex.Label()),
76-
zap.Int64("id", vertex.ID()),
76+
zap.Any("id", vertex.ID()),
7777
)
7878
}
7979
}

gremconnect/response.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ func MarshalResponse(msg []byte) (Response, error) {
5353
code = status["code"].(float64)
5454
resp = Response{Code: int(code)}
5555
)
56+
message, _ := status["message"].(string)
5657

57-
err = responseDetectError(resp.Code)
58+
err = responseDetectError(resp.Code, message)
5859
if err != nil {
5960
resp.Data = err // Use the Data field as a vehicle for the error.
6061
} else {
@@ -67,7 +68,7 @@ func MarshalResponse(msg []byte) (Response, error) {
6768

6869
// responseDetectError detects any possible errors in responses
6970
// from Gremlin Server and generates an error for each code
70-
func responseDetectError(code int) error {
71+
func responseDetectError(code int, message string) error {
7172
switch code {
7273
case 200:
7374
break
@@ -76,25 +77,25 @@ func responseDetectError(code int) error {
7677
case 206:
7778
break
7879
case 401:
79-
return gremerror.NewNetworkError(401, "UNAUTHORIZED")
80+
return gremerror.NewNetworkError(401, "UNAUTHORIZED", message)
8081
case 407:
81-
return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED")
82+
return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", message)
8283
case 498:
83-
return gremerror.NewNetworkError(498, "MALFORMED REQUEST")
84+
return gremerror.NewNetworkError(498, "MALFORMED REQUEST", message)
8485
case 499:
85-
return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS")
86+
return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", message)
8687
case 500:
87-
return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR")
88+
return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", message)
8889
case 503:
89-
return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE")
90+
return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE", message)
9091
case 597:
91-
return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR")
92+
return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", message)
9293
case 598:
93-
return gremerror.NewNetworkError(598, "SERVER TIMEOUT")
94+
return gremerror.NewNetworkError(598, "SERVER TIMEOUT", message)
9495
case 599:
95-
return gremerror.NewNetworkError(599, "SERIALIZATION ERROR")
96+
return gremerror.NewNetworkError(599, "SERIALIZATION ERROR", message)
9697
default:
97-
return gremerror.NewNetworkError(code, "UNKNOWN ERROR")
98+
return gremerror.NewNetworkError(code, "UNKNOWN ERROR", message)
9899
}
99100
return nil
100101
}

gremconnect/response_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var (
7777
{
7878
"requestId": "d2476e5b-b2bc-6a70-2647-3991f68ab415",
7979
"status": {
80+
"message": "Some error",
8081
"code": 401,
8182
"attributes": {}
8283
},
@@ -233,67 +234,67 @@ func TestMarshalRespone(t *testing.T) {
233234
})
234235

235236
Convey("And resp401.Data should be 'UNAUTHORIZED'", func() {
236-
So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED"))
237+
So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED", "Some error"))
237238
})
238239

239240
Convey("Then the status code should be 407", func() {
240241
So(resp407.Code, ShouldEqual, 407)
241242
})
242243

243244
Convey("And resp407.Data should be 'AUTHENTICATE'", func() {
244-
So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED"))
245+
So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", ""))
245246
})
246247

247248
Convey("Then the status code should be 498", func() {
248249
So(resp498.Code, ShouldEqual, 498)
249250
})
250251

251252
Convey("And resp498.Data should be 'MALFORMED REQUEST", func() {
252-
So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST"))
253+
So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST", ""))
253254
})
254255

255256
Convey("Then the status code should be 499", func() {
256257
So(resp499.Code, ShouldEqual, 499)
257258
})
258259

259260
Convey("And resp499.Data should be 'INVALID REQUEST ARGUMENTS'", func() {
260-
So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS"))
261+
So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", ""))
261262
})
262263

263264
Convey("Then the status code should be 500", func() {
264265
So(resp500.Code, ShouldEqual, 500)
265266
})
266267

267268
Convey("And resp500.Data should be 'SERVER ERROR'", func() {
268-
So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR"))
269+
So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", ""))
269270
})
270271

271272
Convey("Then the status code should be 597", func() {
272273
So(resp597.Code, ShouldEqual, 597)
273274
})
274275

275276
Convey("And resp597.Data should be 'SCRIPT EVALUATION ERROR'", func() {
276-
So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR"))
277+
So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", ""))
277278
})
278279

279280
Convey("Then the status code should be 598", func() {
280281
So(resp598.Code, ShouldEqual, 598)
281282
})
282283

283284
Convey("And resp598.Data should be 'SERVER TIMEOUT'", func() {
284-
So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT"))
285+
So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT", ""))
285286
})
286287

287288
Convey("Then the status code should be 599", func() {
288289
So(resp599.Code, ShouldEqual, 599)
289290
})
290291

291292
Convey("And resp599.Data should be 'SERVER SERIALIZATION ERROR'", func() {
292-
So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR"))
293+
So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR", ""))
293294
})
294295

295296
Convey("Then respDefault.Data should be 'UNKNOWN ERROR'", func() {
296-
So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR"))
297+
So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR", ""))
297298
})
298299
})
299300
})

gremerror/networkerror.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import "strconv"
2626
type NetworkError struct {
2727
statusCode int
2828
msg string
29+
origMsg string
2930
}
3031

3132
// NewNetworkError returns a status code related error.
32-
func NewNetworkError(statusCode int, msg string) error {
33+
func NewNetworkError(statusCode int, msg string, origMsg string) error {
3334
return &NetworkError{
3435
statusCode: statusCode,
3536
msg: msg,
37+
origMsg: origMsg,
3638
}
3739
}
3840

@@ -41,5 +43,6 @@ func (g *NetworkError) Error() string {
4143
fmtError("type", "NETWORK_ERROR"),
4244
fmtError("status code", strconv.Itoa(g.statusCode)),
4345
fmtError("error", g.msg),
46+
fmtError("original error", g.origMsg),
4447
)
4548
}

manager/addvertex_test.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ import (
3434
var testVertex = model.Vertex{
3535
Type: "testType",
3636
Value: model.VertexValue{
37-
ID: model.ID{
38-
Type: "testID",
39-
Value: 1234,
40-
},
37+
ID: 1234,
4138
Label: "testLabel",
4239
Properties: model.PropertyMap{"testDetail": []model.Property{
43-
model.Property{
40+
{
4441
Type: "testType",
4542
Value: model.PropertyValue{
4643
ID: model.PropertyID{
47-
Type: "testIDType",
48-
Value: model.PropertyIDValue{
49-
RelationID: "testRelID",
50-
},
44+
Type: "testIDType",
45+
Value: "testRelID",
5146
},
5247
Value: model.ValueWrapper{
5348
PropertyDetailedValue: model.PropertyDetailedValue{
@@ -76,7 +71,7 @@ func TestAddAPIVertex(t *testing.T) {
7671
data.Properties = map[string]string{"testkey": "testval"}
7772
v, _ := qm.AddAPIVertex(data)
7873
Convey("Then the return vertex ID value should be 28720", func() {
79-
So(v.Value.ID.Value, ShouldEqual, 28720)
74+
So(v.Value.ID, ShouldEqual, 28720)
8075
})
8176
})
8277
})
@@ -103,7 +98,7 @@ func TestAddVertexByStruct(t *testing.T) {
10398
Convey("When AddVertexByStruct is called", func() {
10499
res, _ := qm.AddVertexByStruct(testVertex)
105100
Convey("Then the return vertex ID value should be 28720", func() {
106-
So(res.Value.ID.Value, ShouldEqual, 28720)
101+
So(res.Value.ID, ShouldEqual, 28720)
107102
})
108103
})
109104
})
@@ -169,7 +164,7 @@ func TestAddVertexByQuery(t *testing.T) {
169164
var q mockQuery
170165
res, _ := qm.AddVertexByQuery(q)
171166
Convey("Then the return vertex ID value should be 28720", func() {
172-
So(res.Value.ID.Value, ShouldEqual, 28720)
167+
So(res.Value.ID, ShouldEqual, 28720)
173168
})
174169
})
175170
})

manager/dropvertex.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (v *dropQueryManager) DropVertexLabel(label string) error {
5353
return nil
5454
}
5555

56-
func (v *dropQueryManager) DropVertexByID(ids ...int64) error {
56+
func (v *dropQueryManager) DropVertexByID(ids ...interface{}) error {
5757
var err error
5858
for _, id := range ids {
5959
query := traversal.NewTraversal().V().HasID(id).Drop()

0 commit comments

Comments
 (0)