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

Feature/grip client context #309

Merged
merged 2 commits into from
Apr 15, 2024
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
5 changes: 3 additions & 2 deletions cmd/dump/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dump

import (
"context"
"fmt"

"github.com/bmeg/grip/gripql"
Expand Down Expand Up @@ -29,7 +30,7 @@ var Cmd = &cobra.Command{

if vertexDump {
q := gripql.V()
elems, err := conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: q.Statements})
elems, err := conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: q.Statements})
if err != nil {
return err
}
Expand All @@ -44,7 +45,7 @@ var Cmd = &cobra.Command{

if edgeDump {
q := gripql.E()
elems, err := conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: q.Statements})
elems, err := conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: q.Statements})
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/info/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package info

import (
"context"
"fmt"

"github.com/bmeg/grip/gripql"
Expand All @@ -27,7 +28,7 @@ var Cmd = &cobra.Command{
fmt.Printf("Graph: %s\n", graph)

q := gripql.V().Count()
res, err := conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: q.Statements})
res, err := conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: q.Statements})
if err != nil {
return err
}
Expand All @@ -36,7 +37,7 @@ var Cmd = &cobra.Command{
}

q = gripql.E().Count()
res, err = conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: q.Statements})
res, err = conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: q.Statements})
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package query

import (
"context"
"fmt"

"github.com/bmeg/grip/gripql"
Expand Down Expand Up @@ -47,7 +48,7 @@ Example:
}

log.Debugf("Query: %s\n", query.String())
res, err := conn.Traversal(query)
res, err := conn.Traversal(context.Background(), query)
if err != nil {
log.Errorf("Traversal error: %s", err)
return err
Expand Down
4 changes: 2 additions & 2 deletions gripql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ func (client Client) GetVertex(graph string, id string) (*Vertex, error) {
}

// Traversal runs a graph traversal query
func (client Client) Traversal(query *GraphQuery) (chan *QueryResult, error) {
func (client Client) Traversal(ctx context.Context, query *GraphQuery) (chan *QueryResult, error) {
out := make(chan *QueryResult, 100)
tclient, err := client.QueryC.Traversal(context.Background(), query)
tclient, err := client.QueryC.Traversal(ctx, query)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion gripql/schema/scan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package schema

import (
"context"

"github.com/bmeg/grip/gripql"
"github.com/bmeg/grip/log"
"github.com/bmeg/grip/util"
Expand Down Expand Up @@ -40,7 +42,7 @@ func ScanSchema(conn gripql.Client, graph string, sampleCount uint32, exclude []
schema := map[string]interface{}{}
log.Infof("Scanning %s\n", label)
nodeQuery := gripql.V().HasLabel(label).Limit(sampleCount)
nodeRes, err := conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: nodeQuery.Statements})
nodeRes, err := conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: nodeQuery.Statements})
if err == nil {
for row := range nodeRes {
v := row.GetVertex()
Expand Down
4 changes: 2 additions & 2 deletions server/metagraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func (server *GripServer) getGraph(graph string) (*gripql.Graph, error) {
if err != nil {
return nil, fmt.Errorf("failed to load existing schema: %v", err)
}
res, err := conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: gripql.NewQuery().V().Statements})
res, err := conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: gripql.NewQuery().V().Statements})
if err != nil {
return nil, fmt.Errorf("failed to load existing schema: %v", err)
}
vertices := []*gripql.Vertex{}
for row := range res {
vertices = append(vertices, row.GetVertex())
}
res, err = conn.Traversal(&gripql.GraphQuery{Graph: graph, Query: gripql.NewQuery().E().Statements})
res, err = conn.Traversal(context.Background(), &gripql.GraphQuery{Graph: graph, Query: gripql.NewQuery().E().Statements})
if err != nil {
return nil, fmt.Errorf("failed to load existing schema: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestBasicAuthFail(t *testing.T) {
t.Fatal(err)
}

_, err = cli.Traversal(&gripql.GraphQuery{Graph: "test", Query: gripql.NewQuery().V().Statements})
_, err = cli.Traversal(context.Background(), &gripql.GraphQuery{Graph: "test", Query: gripql.NewQuery().V().Statements})
if err == nil || !strings.Contains(err.Error(), "PermissionDenied") {
t.Errorf("expected PermissionDenied error; got: %v", err)
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestBasicAuth(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}

_, err = cli.Traversal(&gripql.GraphQuery{Graph: "test", Query: gripql.NewQuery().V().Statements})
_, err = cli.Traversal(context.Background(), &gripql.GraphQuery{Graph: "test", Query: gripql.NewQuery().V().Statements})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down
Loading