MCPcopy
hub / github.com/dgraph-io/dgraph / mutationHandler

Function mutationHandler

dgraph/cmd/alpha/http.go:345–508  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

343}
344
345func mutationHandler(w http.ResponseWriter, r *http.Request) {
346 if commonHandler(w, r) {
347 return
348 }
349
350 commitNow, err := parseBool(r, "commitNow")
351 if err != nil {
352 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
353 return
354 }
355 startTs, err := parseUint64(r, "startTs")
356 hash := r.URL.Query().Get("hash")
357 if err != nil {
358 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
359 return
360 }
361 body := readRequest(w, r)
362 if body == nil {
363 return
364 }
365
366 // start parsing the query
367 parseStart := time.Now()
368
369 var req *api.Request
370 contentType := r.Header.Get("Content-Type")
371 mediaType, contentTypeParams, err := mime.ParseMediaType(contentType)
372 if err != nil {
373 x.SetStatus(w, x.ErrorInvalidRequest, "Invalid Content-Type")
374 }
375 if charset, ok := contentTypeParams["charset"]; ok && strings.ToLower(charset) != "utf-8" {
376 x.SetStatus(w, x.ErrorInvalidRequest, "Unsupported charset. "+
377 "Supported charset is UTF-8")
378 return
379 }
380
381 switch mediaType {
382 case "application/json":
383 ms := make(map[string]*skipJSONUnmarshal)
384 if err := json.Unmarshal(body, &ms); err != nil {
385 jsonErr := convertJSONError(string(body), err)
386 x.SetStatus(w, x.ErrorInvalidRequest, jsonErr.Error())
387 return
388 }
389
390 req = &api.Request{}
391 if queryText, ok := ms["query"]; ok && queryText != nil {
392 req.Query, err = strconv.Unquote(string(queryText.bs))
393 if err != nil {
394 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
395 return
396 }
397 }
398
399 // JSON API support both keys 1. mutations 2. set,delete,cond
400 // We want to maintain the backward compatibility of the API here.
401 extractMutation := func(jsMap map[string]*skipJSONUnmarshal) (*api.Mutation, error) {
402 mu := &api.Mutation{}

Callers

nothing calls this directly

Calls 15

SetStatusFunction · 0.92
ParseDQLFunction · 0.92
AttachAccessJwtFunction · 0.92
SetStatusWithDataFunction · 0.92
WriteResponseFunction · 0.92
commonHandlerFunction · 0.85
parseBoolFunction · 0.85
parseUint64Function · 0.85
readRequestFunction · 0.85
convertJSONErrorFunction · 0.85
QueryNoGrpcMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected