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

Method doMutate

edgraph/server.go:575–713  ·  view source on GitHub ↗
(ctx context.Context, qc *queryContext, resp *api.Response)

Source from the content-addressed store, hash-verified

573}
574
575func (s *Server) doMutate(ctx context.Context, qc *queryContext, resp *api.Response) error {
576 if len(qc.gmuList) == 0 {
577 return nil
578 }
579 if ctx.Err() != nil {
580 return ctx.Err()
581 }
582
583 start := time.Now()
584 defer func() {
585 qc.latency.Processing += time.Since(start)
586 }()
587
588 if !isMutationAllowed(ctx) {
589 return errors.Errorf("no mutations allowed")
590 }
591
592 // update mutations from the query results before assigning UIDs
593 if err := updateMutations(qc); err != nil {
594 return err
595 }
596
597 if err := verifyUniqueWithinMutation(qc); err != nil {
598 return err
599 }
600
601 newUids, err := query.AssignUids(ctx, qc.gmuList)
602 if err != nil {
603 return err
604 }
605
606 // resp.Uids contains a map of the node name to the uid.
607 // 1. For a blank node, like _:foo, the key would be foo.
608 // 2. For a uid variable that is part of an upsert query,
609 // like uid(foo), the key would be uid(foo).
610 resp.Uids = query.UidsToHex(query.StripBlankNode(newUids))
611 edges, err := query.ToDirectedEdges(qc.gmuList, newUids)
612 if err != nil {
613 return err
614 }
615
616 if len(edges) > x.Config.LimitMutationsNquad {
617 return errors.Errorf("NQuad count in the request: %d, is more that threshold: %d",
618 len(edges), x.Config.LimitMutationsNquad)
619 }
620
621 ns, err := x.ExtractNamespace(ctx)
622 if err != nil {
623 return errors.Wrapf(err, "While doing mutations:")
624 }
625 predHints := make(map[string]pb.Metadata_HintType)
626 for _, gmu := range qc.gmuList {
627 for pred, hint := range gmu.Metadata.GetPredHints() {
628 pred = x.NamespaceAttr(ns, pred)
629 if oldHint := predHints[pred]; oldHint == pb.Metadata_LIST {
630 continue
631 }
632 predHints[pred] = hint

Callers 1

doQueryMethod · 0.95

Calls 15

AssignUidsFunction · 0.92
UidsToHexFunction · 0.92
StripBlankNodeFunction · 0.92
ToDirectedEdgesFunction · 0.92
ExtractNamespaceFunction · 0.92
NamespaceAttrFunction · 0.92
ApplyMutationsFunction · 0.92
CommitOverNetworkFunction · 0.92
isMutationAllowedFunction · 0.85
updateMutationsFunction · 0.85
validateMutationFunction · 0.85

Tested by

no test coverage detected