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

IRI fixes for Save in Gizmo #859

Merged
merged 1 commit into from
Oct 14, 2019
Merged
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
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