Skip to content

Commit

Permalink
gizmo: accept a single value in save(); proper tags in JSON-LD; fix #856
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Oct 14, 2019
1 parent 3af81ed commit a5c3183
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions query/gizmo/gizmo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down
25 changes: 22 additions & 3 deletions query/gizmo/traversals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
}
Expand All @@ -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 {
Expand Down

0 comments on commit a5c3183

Please sign in to comment.