Skip to content

Commit

Permalink
Revert "Add support for *API* required for Multiple Mutation (#3839)"
Browse files Browse the repository at this point in the history
This reverts commit abc64ce.
  • Loading branch information
MichaelJCompton committed Sep 4, 2019
1 parent 40e3682 commit a7e5c3c
Show file tree
Hide file tree
Showing 26 changed files with 2,251 additions and 1,717 deletions.
2 changes: 1 addition & 1 deletion contrib/integration/bigdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
// schema items.
resp, err := c.NewTxn().Query(ctx, "schema {}")
x.Check(err)
if len(resp.Json) < 5 {
if len(resp.Schema) < 5 {
// Run each schema alter separately so that there is an even
// distribution among all groups.
for _, s := range schema() {
Expand Down
9 changes: 3 additions & 6 deletions contrib/integration/testtxn/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,12 @@ func TestTxnRead5(t *testing.T) {
mu = &api.Mutation{}
mu.SetJson = []byte(fmt.Sprintf("{\"uid\": \"%s\", \"name\": \"Manish2\"}", uid))

muReq := api.Request{
Mutations: []*api.Mutation{mu},
CommitNow: true,
}
res, err := dc.Query(context.Background(), &muReq)
mu.CommitNow = true
res, err := dc.Mutate(context.Background(), mu)
if err != nil {
log.Fatalf("Error while running mutation: %v\n", err)
}
x.AssertTrue(res.Txn.StartTs > 0)
x.AssertTrue(res.Context.StartTs > 0)
resp, err = dc.Query(context.Background(), &req)
if err != nil {
log.Fatalf("Error while running query: %v\n", err)
Expand Down
27 changes: 13 additions & 14 deletions dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {
// start parsing the query
parseStart := time.Now()

var req *api.Request
var mu *api.Mutation
contentType := r.Header.Get("Content-Type")
switch strings.ToLower(contentType) {
case "application/json":
Expand All @@ -312,16 +312,15 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {
return
}

mu := &api.Mutation{}
req = &api.Request{Mutations: []*api.Mutation{mu}}
mu = &api.Mutation{}
if setJSON, ok := ms["set"]; ok && setJSON != nil {
mu.SetJson = setJSON.bs
}
if delJSON, ok := ms["delete"]; ok && delJSON != nil {
mu.DeleteJson = delJSON.bs
}
if queryText, ok := ms["query"]; ok && queryText != nil {
req.Query, err = strconv.Unquote(string(queryText.bs))
mu.Query, err = strconv.Unquote(string(queryText.bs))
if err != nil {
x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
return
Expand All @@ -337,7 +336,7 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {

case "application/rdf":
// Parse N-Quads.
req, err = gql.ParseMutation(string(body))
mu, err = gql.ParseMutation(string(body))
if err != nil {
x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
return
Expand All @@ -352,26 +351,26 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {
// end of query parsing
parseEnd := time.Now()

req.StartTs = startTs
req.CommitNow = commitNow
mu.StartTs = startTs
mu.CommitNow = commitNow

ctx := attachAccessJwt(context.Background(), r)
resp, err := (&edgraph.Server{}).Query(ctx, req)
resp, err := (&edgraph.Server{}).Mutate(ctx, mu)
if err != nil {
x.SetStatusWithData(w, x.ErrorInvalidRequest, err.Error())
return
}

resp.Latency.ParsingNs = uint64(parseEnd.Sub(parseStart).Nanoseconds())
e := query.Extensions{
Txn: resp.Txn,
Txn: resp.Context,
Latency: resp.Latency,
}
sort.Strings(e.Txn.Keys)
sort.Strings(e.Txn.Preds)

// Don't send keys array which is part of txn context if its commit immediately.
if req.CommitNow {
if mu.CommitNow {
e.Txn.Keys = e.Txn.Keys[:0]
}

Expand Down Expand Up @@ -488,11 +487,11 @@ func handleCommit(startTs uint64, reqText []byte) (map[string]interface{}, error
return nil, err
}

resp := &api.Response{}
resp.Txn = tc
resp.Txn.CommitTs = cts
resp := &api.Assigned{}
resp.Context = tc
resp.Context.CommitTs = cts
e := query.Extensions{
Txn: resp.Txn,
Txn: resp.Context,
}
e.Txn.Keys = e.Txn.Keys[:0]
response := map[string]interface{}{}
Expand Down
227 changes: 0 additions & 227 deletions dgraph/cmd/alpha/upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,230 +1244,3 @@ upsert {
_, _, _, err := mutationWithTs(m1, "application/rdf", false, true, 0)
require.Contains(t, err.Error(), "Matching brackets not found")
}

func TestUpsertDeleteOnlyYourPost(t *testing.T) {
require.NoError(t, dropAll())
require.NoError(t, alterSchema(`
name: string @index(exact) .
content: string @index(exact) .`))

m1 := `
{
set {
_:user1 <name> "user1" .
_:user2 <name> "user2" .
_:user3 <name> "user3" .
_:user4 <name> "user4" .
_:post1 <content> "post1" .
_:post1 <author> _:user1 .
_:post2 <content> "post2" .
_:post2 <author> _:user1 .
_:post3 <content> "post3" .
_:post3 <author> _:user2 .
_:post4 <content> "post4" .
_:post4 <author> _:user3 .
_:post5 <content> "post5" .
_:post5 <author> _:user3 .
_:post6 <content> "post6" .
_:post6 <author> _:user3 .
}
}`

_, _, _, err := mutationWithTs(m1, "application/rdf", false, true, 0)
require.NoError(t, err)

// user2 trying to delete the post4
m2 := `
upsert {
query {
var(func: eq(content, "post4")) {
p4 as uid
author {
n3 as name
}
}
u2 as var(func: eq(val(n3), "user2"))
}
mutation @if(eq(len(u2), 1)) {
delete {
uid(p4) <content> * .
uid(p4) <author> * .
}
}
}`
_, _, _, err = mutationWithTs(m2, "application/rdf", false, true, 0)
require.NoError(t, err)

// post4 must still exist
q2 := `
{
post(func: eq(content, "post4")) {
content
}
}`
res, _, err := queryWithTs(q2, "application/graphql+-", "", 0)
require.NoError(t, err)
require.Contains(t, res, "post4")

// user3 deleting the post4
m3 := `
upsert {
query {
var(func: eq(content, "post4")) {
p4 as uid
author {
n3 as name
}
}
u4 as var(func: eq(val(n3), "user3"))
}
mutation @if(eq(len(u4), 1)) {
delete {
uid(p4) <content> * .
uid(p4) <author> * .
}
}
}`
_, _, _, err = mutationWithTs(m3, "application/rdf", false, true, 0)
require.NoError(t, err)

// post4 shouldn't exist anymore
res, _, err = queryWithTs(q2, "application/graphql+-", "", 0)
require.NoError(t, err)
require.NotContains(t, res, "post4")
}

func TestUpsertBulkUpdateBranch(t *testing.T) {
require.NoError(t, dropAll())
require.NoError(t, alterSchema(`
name: string @index(exact) .
branch: string .`))

m1 := `
{
set {
_:user1 <name> "user1" .
_:user1 <branch> "Fuller Street, San Francisco" .
_:user2 <name> "user2" .
_:user2 <branch> "Fuller Street, San Francisco" .
_:user3 <name> "user3" .
_:user3 <branch> "Fuller Street, San Francisco" .
}
}`

_, _, _, err := mutationWithTs(m1, "application/rdf", false, true, 0)
require.NoError(t, err)

// Bulk Update: update everyone's branch
m2 := `
upsert {
query {
u as var(func: has(branch))
}
mutation {
set {
uid(u) <branch> "Fuller Street, SF" .
}
}
}`
_, _, _, err = mutationWithTs(m2, "application/rdf", false, true, 0)
require.NoError(t, err)

q2 := `
{
q(func: has(branch)) {
name
branch
}
}`
res, _, err := queryWithTs(q2, "application/graphql+-", "", 0)
require.NoError(t, err)
require.NotContains(t, res, "San Francisco")
require.Contains(t, res, "user1")
require.Contains(t, res, "user2")
require.Contains(t, res, "user3")
require.Contains(t, res, "Fuller Street, SF")

// Bulk Delete: delete everyone's branch
m3 := `
upsert {
query {
u as var(func: has(branch))
}
mutation {
delete {
uid(u) <branch> * .
}
}
}`
_, _, _, err = mutationWithTs(m3, "application/rdf", false, true, 0)
require.NoError(t, err)

res, _, err = queryWithTs(q2, "application/graphql+-", "", 0)
require.NoError(t, err)
require.NotContains(t, res, "San Francisco")
require.NotContains(t, res, "Fuller Street, SF")
}

func TestDeleteCountIndex(t *testing.T) {
require.NoError(t, dropAll())
require.NoError(t, alterSchema(`
<game_answer>: uid @count @reverse .
<name>: int @index(int) .`))

m1 := `
{
set {
_:1 <game_answer> _:2 .
_:1 <name> "1" .
_:2 <game_answer> _:3 .
_:2 <name> "2" .
_:4 <game_answer> _:2 .
_:3 <name> "3" .
_:4 <name> "4" .
}
}`

_, _, _, err := mutationWithTs(m1, "application/rdf", false, true, 0)
require.NoError(t, err)

m2 := `
upsert {
query {
u3 as var(func: eq(name, "3"))
u2 as var(func: eq(name, "2"))
}
mutation {
delete {
uid(u2) <game_answer> uid(u3) .
}
}
}`
_, _, _, err = mutationWithTs(m2, "application/rdf", false, true, 0)
require.NoError(t, err)

q1 := `
{
me(func: eq(count(~game_answer), 1)) {
name
count(~game_answer)
}
}`
res, _, err := queryWithTs(q1, "application/graphql+-", "", 0)
require.NoError(t, err)
require.NotContains(t, res, "count(~game_answer)")
}
2 changes: 1 addition & 1 deletion edgraph/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func authorizeMutation(ctx context.Context, gmu *gql.Mutation) error {
return nil
}

func authorizeQuery(ctx context.Context, parsedReq *gql.Result) error {
func authorizeQuery(ctx context.Context, req *api.Request) error {
// always allow access
return nil
}
Loading

0 comments on commit a7e5c3c

Please sign in to comment.