Repository: cayleygraph/cayley
Pull request #858 (2019-10-14 05:27:01)

Fix build without packr resources
Currently, the build of a binary requires a `packr2` command to be run. This PR adds a dummy file to the packr directory expected by the build to allow compiling without packr resources (fallback to FS).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/cayleygraph/cayley/858)
<!-- Reviewable:end -->



Patch:
diff --git a/.gitignore b/.gitignore
index b809c8c..f87b2c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,5 +12,5 @@ cayley.json
 cayley/
 dist/
 vendor/
-packrd/
+packrd/packed-*
 cayley
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index aa0a512..c659693 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,6 +23,7 @@ cache:
     - $GOPATH/pkg/mod
 
 script:
+  - GO111MODULE=on go build ./cmd/cayley
   - packr2 && GO111MODULE=on go test -v ./...
 
 # TODO(dennwc): snapcraft config
diff --git a/packrd/dummy.go b/packrd/dummy.go
new file mode 100644
index 0000000..02f31bf
--- /dev/null
+++ b/packrd/dummy.go
@@ -0,0 +1,5 @@
+package packrd
+
+import _ "github.com/gobuffalo/packr/v2"
+
+// This file exists to allow building the binary without embedded data.
diff --git a/query/gizmo/traversals.go b/query/gizmo/traversals.go
index 4035ddf..171a5d6 100644
--- a/query/gizmo/traversals.go
+++ b/query/gizmo/traversals.go
@@ -26,6 +26,8 @@ import (
 	"github.com/cayleygraph/cayley/graph/iterator"
 	"github.com/cayleygraph/cayley/graph/path"
 	"github.com/cayleygraph/cayley/graph/shape"
+	"github.com/cayleygraph/cayley/query"
+	"github.com/cayleygraph/quad"
 )
 
 // pathObject is a Path object in Gizmo.
@@ -452,7 +454,7 @@ func (p *pathObject) save(call goja.FunctionCall, rev, opt bool) goja.Value {
 	if len(args) > 2 || len(args) == 0 {
 		return throwErr(p.s.vm, errArgCount{Got: len(args)})
 	}
-	vtag := args[0]
+	var vtag interface{} = ""
 	if len(args) == 2 {
 		vtag = args[1]
 	}
@@ -463,12 +465,29 @@ func (p *pathObject) save(call goja.FunctionCall, rev, opt bool) goja.Value {
 	via := args[0]
 	if vp, ok := via.(*pathObject); ok {
 		via = vp.path
+		if tag == "" {
+			return throwErr(p.s.vm, errors.New("must specify a tag name when saving a path"))
+		}
 	} else {
-		var err error
-		via, err = toQuadValue(via)
+		qv, err := toQuadValue(via)
+		via = qv
 		if err != nil {
 			return throwErr(p.s.vm, err)
 		}
+		if tag == "" {
+			if p.s.col == query.JSONLD {
+				switch qv := qv.(type) {
+				case quad.IRI:
+					tag = string(qv)
+				case quad.String:
+					tag = string(qv)
+				default:
+					tag = quad.StringOf(qv)
+				}
+			} else {
+				tag = quad.StringOf(qv)
+			}
+		}
 	}
 	np := p.clonePath()
 	if opt {


Test patch:
diff --git a/query/gizmo/gizmo_test.go b/query/gizmo/gizmo_test.go
index 44060a9..6adb94f 100644
--- a/query/gizmo/gizmo_test.go
+++ b/query/gizmo/gizmo_test.go
@@ -415,6 +415,14 @@ var testQueries = []struct {
 		tag:    "somecool",
 		expect: []string{"cool_person", "cool_person"},
 	},
+	{
+		message: "save iri no tag",
+		query: `
+			g.V().save(g.IRI("status")).all()
+		`,
+		tag:    "<status>",
+		expect: []string{"cool_person", "cool_person", "cool_person", "smart_person", "smart_person"},
+	},
 	{
 		message: "show a simple saveR",
 		query: `