Skip to content

Commit

Permalink
Remove changes that returned response for upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Nov 6, 2019
1 parent eb3e3a5 commit 6f56d10
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 188 deletions.
10 changes: 1 addition & 9 deletions dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 14 additions & 11 deletions dgraph/cmd/alpha/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) (
Expand All @@ -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
}

Expand Down
Loading

0 comments on commit 6f56d10

Please sign in to comment.