diff --git a/dgraph/cmd/alpha/http.go b/dgraph/cmd/alpha/http.go index a6389f0b1f4..f7ea32c4dd9 100644 --- a/dgraph/cmd/alpha/http.go +++ b/dgraph/cmd/alpha/http.go @@ -21,7 +21,6 @@ import ( "compress/gzip" "context" "encoding/json" - "fmt" "io" "io/ioutil" "net/http" @@ -388,14 +387,7 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) { mp["code"] = x.Success mp["message"] = "Done" mp["uids"] = resp.Uids - if len(resp.Vars) > 0 { - vars := make(map[string][]string) - // Flatten the mutated map so that it is easier to parse for the client. - for v, uids := range resp.Vars { - vars[fmt.Sprintf("uid(%s)", v)] = uids.GetUids() - } - mp["vars"] = vars - } + mp["result"] = json.RawMessage(resp.Json) response["data"] = mp js, err := json.Marshal(response) diff --git a/dgraph/cmd/alpha/http_test.go b/dgraph/cmd/alpha/http_test.go index c3f5211ef3c..38794454cbd 100644 --- a/dgraph/cmd/alpha/http_test.go +++ b/dgraph/cmd/alpha/http_test.go @@ -162,11 +162,21 @@ func queryWithTs(queryText, contentType, debug string, ts uint64) (string, uint6 return string(output), startTs, err } +type muRes struct { + Data struct { + Uids map[string]string `json:"uids,omitempty"` + Result json.RawMessage `json:"result,omitempty"` + } `json:"data,omitempty"` + Extensions *query.Extensions `json:"extensions,omitempty"` + Errors []x.GqlError `json:"errors,omitempty"` +} + type mutationResponse struct { keys []string preds []string startTs uint64 - vars map[string][]string + uids map[string]string + result json.RawMessage } func mutationWithTs(m, t string, isJson bool, commitNow bool, ts uint64) ( @@ -188,23 +198,16 @@ func mutationWithTs(m, t string, isJson bool, commitNow bool, ts uint64) ( return mr, err } - var r res + var r muRes if err := json.Unmarshal(body, &r); err != nil { return mr, err } - type resData struct { - MutationVars map[string][]string `json:"vars"` - } - var rd resData - if err := json.Unmarshal(r.Data, &rd); err != nil { - return mr, err - } - - mr.vars = rd.MutationVars mr.keys = r.Extensions.Txn.Keys mr.preds = r.Extensions.Txn.Preds mr.startTs = r.Extensions.Txn.StartTs + mr.uids = r.Data.Uids + mr.result = r.Data.Result return mr, nil } diff --git a/dgraph/cmd/alpha/upsert_test.go b/dgraph/cmd/alpha/upsert_test.go index 01c09a502f8..ea9b0c79e55 100644 --- a/dgraph/cmd/alpha/upsert_test.go +++ b/dgraph/cmd/alpha/upsert_test.go @@ -18,9 +18,8 @@ package alpha import ( "context" + "encoding/json" "fmt" - "sort" - "strconv" "strings" "sync" "testing" @@ -31,15 +30,15 @@ import ( "github.com/stretchr/testify/require" ) -// assertAsHex checks that uids returned as part of the vars map should be valid hex encoded uids. -func assertAsHex(t *testing.T, vars map[string][]string) { - for _, uids := range vars { - for _, uid := range uids { - require.True(t, strings.HasPrefix(uid, "0x"), "uid: [%v] should be a hex encoded string", uid) - // ParseUint throws an error if the string has 0x prefix, so we need to strip the prefix here. - _, err := strconv.ParseUint(uid[2:], 16, 64) - require.NoErrorf(t, err, "while parsing: [%v] as hex encoded uint64", uid) - } +type QueryResult struct { + Q []struct { + UID string + } + User1 []struct { + UID string + } + User2 []struct { + UID string } } @@ -62,7 +61,7 @@ func TestUpsertExample0(t *testing.T) { m1 := ` upsert { query { - me(func: eq(email, "email@company.io")) { + q(func: eq(email, "email@company.io")) { v as uid } } @@ -77,10 +76,10 @@ upsert { mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.Equal(t, 0, len(mr.vars)) - require.True(t, contains(mr.preds, "email")) - require.True(t, contains(mr.preds, "name")) - assertAsHex(t, mr.vars) + require.Equal(t, []string{"1-email", "1-name"}, mr.preds) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) // query should return the wrong name q1 := ` @@ -99,7 +98,7 @@ upsert { m2 := ` upsert { query { - me(func: eq(email, "email@company.io")) { + q(func: eq(email, "email@company.io")) { v as uid } } @@ -113,12 +112,10 @@ upsert { mr, err = mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.Equal(t, 1, len(mr.vars)) - uids, ok := mr.vars["uid(v)"] - require.True(t, ok) - require.Equal(t, 1, len(uids)) - assertAsHex(t, mr.vars) - require.True(t, contains(mr.preds, "name")) + require.Equal(t, []string{"1-name"}, mr.preds) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.Q)) // query should return correct name res, _, err = queryWithTs(q1, "application/graphql+-", "", 0) @@ -173,7 +170,7 @@ func TestUpsertExampleJSON(t *testing.T) { m1 := ` { - "query": "{ u as var(func: has(amount)) { amt as amount \n updated_amt as math(amt+1)}}", + "query": "{ q(func: has(amount)) { u as uid \n amt as amount \n updated_amt as math(amt+1)}}", "set": [ { "uid": "uid(u)", @@ -184,9 +181,9 @@ func TestUpsertExampleJSON(t *testing.T) { ` mr, err := mutationWithTs(m1, "application/json", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 3, len(mr.vars["uid(u)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 3, len(result.Q)) q1 := ` { @@ -265,7 +262,7 @@ func TestUpsertExample0JSON(t *testing.T) { mr, err = mutationWithTs(m2, "application/json", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "name")) + require.Equal(t, []string{"1-name"}, mr.preds) // query should return correct name res, _, err = queryWithTs(q1, "application/graphql+-", "", 0) @@ -335,13 +332,13 @@ upsert { mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, 0 == len(mr.keys)) - require.True(t, contains(mr.preds, "age")) + require.Equal(t, []string{"1-age"}, mr.preds) // Ensure that another run works too mr, err = mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, 0 == len(mr.keys)) - require.True(t, contains(mr.preds, "age")) + require.Equal(t, []string{"1-age"}, mr.preds) } func TestUpsertInvalidErr(t *testing.T) { @@ -458,7 +455,7 @@ upsert { a as age } - oldest(func: uid(a), orderdesc: val(a), first: 1) { + q(func: uid(a), orderdesc: val(a), first: 1) { u as uid name age @@ -473,9 +470,9 @@ upsert { }` mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.Q)) q1 := ` { @@ -494,7 +491,7 @@ upsert { m2 := ` upsert { query { - user1(func: eq(name@en, "user1")) { + q(func: eq(name@en, "user1")) { u1 as uid } } @@ -507,9 +504,9 @@ upsert { }` mr, err = mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u1)"])) - assertAsHex(t, mr.vars) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.Q)) q2 := ` { @@ -564,10 +561,10 @@ upsert { }` mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 2, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u1)"])) - require.Equal(t, 1, len(mr.vars["uid(u2)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.User1)) + require.Equal(t, 1, len(result.User2)) q1 := ` { @@ -601,10 +598,10 @@ upsert { }` mr, err = mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 2, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u1)"])) - require.Equal(t, 1, len(mr.vars["uid(u2)"])) - assertAsHex(t, mr.vars) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.User1)) + require.Equal(t, 1, len(result.User2)) q2 := ` { @@ -725,10 +722,10 @@ friend: uid @reverse .`)) }` mr, err := mutationWithTs(m1, "application/json", false, true, 0) require.NoError(t, err) - require.Equal(t, 2, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u1)"])) - require.Equal(t, 1, len(mr.vars["uid(u2)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.User1)) + require.Equal(t, 1, len(result.User2)) q1 := ` { @@ -775,7 +772,7 @@ func TestUpsertBlankNodeWithVar(t *testing.T) { m := ` upsert { query { - users(func: eq(name, "user1")) { + q(func: eq(name, "user1")) { u as uid } } @@ -789,8 +786,9 @@ upsert { }` mr, err := mutationWithTs(m, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 0, len(mr.vars)) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) q := ` { @@ -921,10 +919,10 @@ upsert { } }` mr, err := mutationWithTs(m, "application/rdf", false, true, 0) - require.Equal(t, 0, len(mr.vars)) require.NoError(t, err) - assertAsHex(t, mr.vars) - + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) } func TestConditionalUpsertExample0(t *testing.T) { @@ -935,7 +933,7 @@ func TestConditionalUpsertExample0(t *testing.T) { m1 := ` upsert { query { - me(func: eq(email, "email@company.io")) { + q(func: eq(email, "email@company.io")) { v as uid } } @@ -950,14 +948,16 @@ upsert { mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "email")) - require.True(t, contains(mr.preds, "name")) - require.Equal(t, 0, len(mr.vars)) + require.Equal(t, []string{"1-email", "1-name"}, mr.preds) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) // Trying again, should be a NOOP mr, err = mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 0, len(mr.vars)) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) // query should return the wrong name q1 := ` @@ -976,7 +976,7 @@ upsert { m2 := ` upsert { query { - me(func: eq(email, "email@company.io")) { + q(func: eq(email, "email@company.io")) { v as uid } } @@ -990,10 +990,10 @@ upsert { mr, err = mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "name")) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(v)"])) - assertAsHex(t, mr.vars) + require.Equal(t, []string{"1-name"}, mr.preds) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.Q)) // query should return correct name res, _, err = queryWithTs(q1, "application/graphql+-", "", 0) @@ -1008,7 +1008,7 @@ func TestConditionalUpsertExample0JSON(t *testing.T) { // Mutation with wrong name m1 := ` { - "query": "{me(func: eq(email, \"email@company.io\")) {v as uid}}", + "query": "{q(func: eq(email, \"email@company.io\")) {v as uid}}", "cond": " @if(eq(len(v), 0)) ", "set": [ { @@ -1024,7 +1024,9 @@ func TestConditionalUpsertExample0JSON(t *testing.T) { mr, err := mutationWithTs(m1, "application/json", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.Equal(t, 0, len(mr.vars)) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) // query should return the wrong name q1 := ` @@ -1042,7 +1044,7 @@ func TestConditionalUpsertExample0JSON(t *testing.T) { // mutation with correct name m2 := ` { - "query": "{me(func: eq(email, \"email@company.io\")) {v as uid}}", + "query": "{q(func: eq(email, \"email@company.io\")) {v as uid}}", "cond": "@if(eq(len(v), 1))", "set": [ { @@ -1054,10 +1056,10 @@ func TestConditionalUpsertExample0JSON(t *testing.T) { mr, err = mutationWithTs(m2, "application/json", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "name")) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(v)"])) - + require.Equal(t, []string{"1-name"}, mr.preds) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.Q)) // query should return correct name res, _, err = queryWithTs(q1, "application/graphql+-", "", 0) require.NoError(t, err) @@ -1102,7 +1104,7 @@ func TestUpsertMultiValue(t *testing.T) { m2 := ` upsert { query { - me(func: eq(works_for, "company1")) { + q(func: eq(works_for, "company1")) { u as uid } } @@ -1116,12 +1118,10 @@ upsert { mr, err := mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "color")) - require.False(t, contains(mr.preds, "works_for")) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 2, len(mr.vars["uid(u)"])) - assertAsHex(t, mr.vars) - + require.Equal(t, []string{"1-color"}, mr.preds) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 2, len(result.Q)) q2 := ` { q(func: eq(works_for, "%s")) { @@ -1140,8 +1140,12 @@ upsert { m3 := ` upsert { query { - c1 as var(func: eq(works_for, "company1")) - c2 as var(func: eq(works_for, "company2")) + user1(func: eq(works_for, "company1")) { + c1 as uid + } + user2(func: eq(works_for, "company2")) { + c2 as uid + } } mutation @if(le(len(c1), 100) AND lt(len(c2), 100)) { @@ -1156,10 +1160,10 @@ upsert { }` mr, err = mutationWithTs(m3, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 2, len(mr.vars)) - require.Equal(t, 2, len(mr.vars["uid(c1)"])) - require.Equal(t, 2, len(mr.vars["uid(c2)"])) - assertAsHex(t, mr.vars) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 2, len(result.User1)) + require.Equal(t, 2, len(result.User2)) // The following mutation should have no effect on the state of the database m4 := ` @@ -1181,7 +1185,6 @@ upsert { }` mr, err = mutationWithTs(m4, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 0, len(mr.vars)) res, _, err = queryWithTs(fmt.Sprintf(q2, "company1"), "application/graphql+-", "", 0) require.NoError(t, err) @@ -1239,8 +1242,12 @@ upsert { m2 := ` upsert { query { - u1 as var(func: eq(email, "user1@company1.io")) - u3 as var(func: eq(email, "user3@company2.io")) + user1(func: eq(email, "user1@company1.io")) { + u1 as uid + } + user2(func: eq(email, "user3@company2.io")) { + u3 as uid + } } mutation @if(eq(len(u1), 1) AND eq(len(u3), 1)) { @@ -1252,10 +1259,10 @@ upsert { }` mr, err := mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 2, len(mr.vars)) - require.Equal(t, 1, len(mr.vars["uid(u1)"])) - require.Equal(t, 1, len(mr.vars["uid(u3)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 1, len(result.User1)) + require.Equal(t, 1, len(result.User2)) res, _, err = queryWithTs(fmt.Sprintf(q1, "company1"), "application/graphql+-", "", 0) require.NoError(t, err) @@ -1599,11 +1606,8 @@ upsert { // parsed correctly by the val function. // User3 doesn't have all the fields. This test also ensures // that val works when not all records have the values - mr, err := mutationWithTs(m2, "application/rdf", false, true, 0) + _, err = mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 3, len(mr.vars["uid(u)"])) - assertAsHex(t, mr.vars) res, _, err := queryWithTs(q1, "application/graphql+-", "", 0) require.NoError(t, err) @@ -1875,7 +1879,7 @@ func TestAggregateValBulkUpdate(t *testing.T) { m1 := ` upsert { query { - u as var(func: has(amount)) { + u as q(func: has(amount)) { amt as amount } me() { @@ -1891,9 +1895,9 @@ upsert { }` mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 3, len(mr.vars["uid(u)"])) - assertAsHex(t, mr.vars) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 3, len(result.Q)) res, _, err := queryWithTs(q1, "application/graphql+-", "", 0) expectedRes := ` @@ -1926,7 +1930,7 @@ upsert { me() { max_amt as max(val(amt)) } - v as var(func: eq(name, "Michael")) { + v as q(func: eq(name, "Michael")) { amount } } @@ -1939,7 +1943,9 @@ upsert { }` mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 0, len(mr.vars)) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) } func TestUpsertBulkUpdateBranch(t *testing.T) { @@ -1973,7 +1979,9 @@ amount: float .`)) m2 := ` upsert { query { - u as var(func: has(branch)) + q(func: has(branch)) { + u as uid + } } mutation { @@ -1984,8 +1992,9 @@ upsert { }` mr, err := mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 3, len(mr.vars["uid(u)"])) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 3, len(result.Q)) q2 := ` { @@ -2006,7 +2015,9 @@ upsert { m3 := ` upsert { query { - u as var(func: has(branch)) + q(func: has(branch)) { + u as uid + } } mutation { @@ -2017,8 +2028,9 @@ upsert { }` mr, err = mutationWithTs(m3, "application/rdf", false, true, 0) require.NoError(t, err) - require.Equal(t, 1, len(mr.vars)) - require.Equal(t, 3, len(mr.vars["uid(u)"])) + result = QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 3, len(result.Q)) res, _, err = queryWithTs(q2, "application/graphql+-", "", 0) require.NoError(t, err) @@ -2113,9 +2125,12 @@ upsert { }` mr, err := mutationWithTs(m2, "application/rdf", false, true, 0) require.NoError(t, err) - // The uid variable is only used in the query and not in mutation and hence shouldn't be part - // of vars. - require.Equal(t, 0, len(mr.vars)) + // The uid variable is only used in the query and not in mutation + // and hence shouldn't be part of vars. + + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) } func TestMultiMutationEmptyRequest(t *testing.T) { @@ -2175,7 +2190,6 @@ func TestMultiMutationNoUpsert(t *testing.T) { } resp, err := dg.NewTxn().Do(context.Background(), req) require.NoError(t, err) - sort.Strings(resp.Txn.Preds) require.Equal(t, []string{"1-email", "1-name", "1-works_for"}, resp.Txn.Preds) testutil.CompareJSON(t, `{"empty": []}`, string(resp.Json)) } @@ -2187,7 +2201,7 @@ func TestMultipleMutation(t *testing.T) { m1 := ` upsert { query { - me(func: eq(email, "email@company.io")) { + q(func: eq(email, "email@company.io")) { v as uid } } @@ -2209,9 +2223,10 @@ upsert { mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) require.NoError(t, err) require.True(t, len(mr.keys) == 0) - require.True(t, contains(mr.preds, "email")) - require.True(t, contains(mr.preds, "name")) - require.Equal(t, 0, len(mr.vars)) + require.Equal(t, []string{"1-email", "1-name"}, mr.preds) + result := QueryResult{} + require.NoError(t, json.Unmarshal(mr.result, &result)) + require.Equal(t, 0, len(result.Q)) q1 := ` { @@ -2299,8 +2314,8 @@ upsert { // mr, err := mutationWithTs(m1, "application/rdf", false, true, 0) // require.NoError(t, err) // require.True(t, len(mr.keys) == 0) -// require.True(t, contains(mr.preds, "email")) -// require.True(t, contains(mr.preds, "name")) +// require.True(t, []string{"email"}, mr.preds) +// require.True(t, []string{"1-name"}, mr.preds) // require.Equal(t, 0, len(mr.vars)) // q1 := ` diff --git a/edgraph/server.go b/edgraph/server.go index b6099387382..8c2f2de9705 100644 --- a/edgraph/server.go +++ b/edgraph/server.go @@ -787,17 +787,6 @@ func updateMutations(qc *queryContext) { updateUIDInMutations(gmu, qc) updateValInMutations(gmu, qc) } - - // Remove condition vars from the response - for _, v := range qc.condVars { - delete(qc.uidRes, v) - } - // Remove empty valued varibales from the response - for n, v := range qc.uidRes { - if len(v) == 0 { - delete(qc.uidRes, n) - } - } } // findVars finds all the variables used in mutation block @@ -998,30 +987,6 @@ func (s *Server) doMutate(ctx context.Context, qc *queryContext, resp *api.Respo return err } - if len(qc.uidRes) > 0 { - resp.Vars = make(map[string]*api.Uids, len(qc.uidRes)) - for v, uids := range qc.uidRes { - // There could be a lot of these uids which could blow up the response size, especially - // for bulk mutations, hence only return variables which have less than a million uids. - if len(uids) <= 1e6 { - hexUids := make([]string, 0, len(uids)) - // doQueryInUpsert returns uids as base10 string representation. We convert them - // to base16 string so that response format is consistent with assigned uids. - for _, uid := range uids { - u, err := strconv.ParseUint(uid, 10, 64) - if err != nil { - return errors.Errorf("couldn't parse uid: [%v] as base 10 uint64", uid) - } - huid := fmt.Sprintf("%#x", u) - hexUids = append(hexUids, huid) - } - resp.Vars[v] = &api.Uids{ - Uids: hexUids, - } - } - } - } - newUids, err := query.AssignUids(ctx, qc.gmuList) if err != nil { return err diff --git a/go.mod b/go.mod index 65aefb72f28..d7d0895de7c 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/blevesearch/snowballstem v0.0.0-20180110192139-26b06a2c243d // indirect github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd github.com/dgraph-io/badger v0.0.0-20190917133922-cbdef65095c7 - github.com/dgraph-io/dgo/v2 v2.1.1-0.20191011032519-062f5605f6da + github.com/dgraph-io/dgo/v2 v2.1.1-0.20191106095420-9d64a2d0ac17 github.com/dgraph-io/ristretto v0.0.0-20191010170704-2ba187ef9534 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 @@ -22,7 +22,7 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/go-ini/ini v1.39.0 // indirect github.com/go-sql-driver/mysql v0.0.0-20190330032241-c0f6b444ad8f - github.com/gogo/protobuf v1.2.0 + github.com/gogo/protobuf v1.3.1 github.com/golang/geo v0.0.0-20170810003146-31fb0106dc4a github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/golang/protobuf v1.3.2 diff --git a/go.sum b/go.sum index 6fb00798716..23d2d9c6405 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v0.0.0-20190917133922-cbdef65095c7 h1:sXNo2Xtte2hOGeq21YyV3qjsyOScoQqWvLdBKInkQS8= github.com/dgraph-io/badger v0.0.0-20190917133922-cbdef65095c7/go.mod h1:V7oadAIwiqodXo5jT04lP+8ysOAuMFZO5x20VSI94Uc= -github.com/dgraph-io/dgo/v2 v2.1.1-0.20191011032519-062f5605f6da h1:JAadBE19xm15ZsBZ9HOSuQvMiaCKu+NsV5O5Mfb/62M= -github.com/dgraph-io/dgo/v2 v2.1.1-0.20191011032519-062f5605f6da/go.mod h1:R/MTZMGhTo60XSziuKpLXzI1OnVWQCZS5oJjxA8Q1bo= +github.com/dgraph-io/dgo/v2 v2.1.1-0.20191106095420-9d64a2d0ac17 h1:FH1JF0iz4n1rvM7pzzNzuuXq45YSDPSpPgsDUo1Powo= +github.com/dgraph-io/dgo/v2 v2.1.1-0.20191106095420-9d64a2d0ac17/go.mod h1:LJCkLxm5fUMcU+yb8gHFjHt7ChgNuz3YnQQ6MQkmscI= github.com/dgraph-io/ristretto v0.0.0-20190903064322-eb48d2f7ca30 h1:FkdGlqxPjfHKdVUzS5dOSMeOkGjEG7PnR1RLbcEqw88= github.com/dgraph-io/ristretto v0.0.0-20190903064322-eb48d2f7ca30/go.mod h1:UvZmzj8odp3S1nli6yEb1vLME8iJFBrRcw8rAJEiu9Q= github.com/dgraph-io/ristretto v0.0.0-20191010170704-2ba187ef9534 h1:9G6fVccQriMJu4nXwpwLDoy9y31t/KUSLAbPcoBgv+4= @@ -97,6 +97,8 @@ github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/geo v0.0.0-20170810003146-31fb0106dc4a h1:DG/Rx1VnnaqyPhKoPFuU61p4N7lkF5//weoP7QwddNs= github.com/golang/geo v0.0.0-20170810003146-31fb0106dc4a/go.mod h1:vgWZ7cu0fq0KY3PpEHsocXOWJpRtkcbKemU4IUw0M60= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= @@ -138,6 +140,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22 github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -318,6 +321,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/wiki/content/mutations/index.md b/wiki/content/mutations/index.md index 35d6e3f8c6d..ab83d64eff7 100644 --- a/wiki/content/mutations/index.md +++ b/wiki/content/mutations/index.md @@ -988,10 +988,7 @@ Result: "data": { "code": "Success", "message": "Done", - "uids": {}, - "vars": { - "uid(v)": ["0x2"] - } + "uids": {} }, "extensions": {...} } @@ -999,8 +996,7 @@ Result: Here, the query block queries for a user with `email` as `user@company1.io`. It stores the `uid` of the user in variable `v`. The mutation block then updates the `age` of the -user by extracting the uid from the variable `v` using `uid` function. We also get `uid(v)` as part -of `vars` which has a list of uids that were used in the set mutation. +user by extracting the uid from the variable `v` using `uid` function. We can achieve the same result using `json` dataset as follows: @@ -1049,10 +1045,7 @@ Result: "data": { "code": "Success", "message": "Done", - "uids": {}, - "vars": { - "uid(v)": ["0x2"] - } + "uids": {} }, "extensions": {...} }