Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding update option to graph edit methods #45

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ proto:
--grpc-gateway_out=logtostderr=true:. \
aql.proto

proto-tool:
go get github.com/golang/protobuf/protoc-gen-go
go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/


# Automatially update code formatting
tidy:
@for f in $$(find ./ -name "*.go" -print | egrep -v "\.pb\.go|\.gw\.go|underscore\.go"); do \
Expand All @@ -47,6 +52,7 @@ lint:
test:
@go test $(TESTS)


# Build binaries for all OS/Architectures
cross-compile: depends
@echo '=== Cross compiling... ==='
Expand Down
11 changes: 9 additions & 2 deletions aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ def __init__(self, url, name):
def query(self):
return Query(self)

def addVertex(self, id, label, prop={}):
def addVertex(self, id, label, prop={}, update=False):
payload = json.dumps({
"gid" : id,
"label" : label,
"data" : prop
})
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
request = urllib2.Request(self.url + "/" + self.name + "/vertex", payload, headers=headers)
url = self.url + "/" + self.name + "/vertex"
if update:
url += "?update=true"
print url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the debug line.

Also, why is this using a URL parameter? Shouldn't it be part of the request document?

request = urllib2.Request(url, payload, headers=headers)
response = urllib2.urlopen(request)
result = response.read()
return json.loads(result)

def updateVertex(self, id, label, prop={}):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing corresponding updateEdge and addEdge(update=True)

self.addVertex(id, label, prop, True)

def addEdge(self, src, dst, label, prop={}):
payload = json.dumps({
"from" : src,
Expand Down
177 changes: 93 additions & 84 deletions aql/aql.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aql/aql.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ message GraphElement {
Vertex vertex = 2;
Edge edge = 3;
Bundle bundle = 4;
bool update = 5;
}

message Graph {
Expand Down
23 changes: 23 additions & 0 deletions conformance/tests/ot_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@



def test_update(O):
errors = []
#print O.query().addV("vertex1").property("field1", {"test" : 1, "value" : False}).render()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to commit commented code.

O.addVertex("vertex1", "person", {"test" : 1, "value" : False} )
O.updateVertex("vertex1", "person", {"value" : True, "other":True} )
#print "vertices", O.query().V().execute()
count = 0
for i in O.query().V().execute():
count += 1
p = i['vertex']['data']
if "test" not in p or "value" not in p:
errors.append("missing keys in structure field")
continue
if p["test"] != 1 or p["value"] != True:
errors.append("Incorrect values in structure")

if count != 1:
errors.append("Vertex struct property count failed")

return errors
Loading