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

Function ExpandEdges

query/mutation.go:51–117  ·  view source on GitHub ↗
(ctx context.Context, m *pb.Mutations)

Source from the content-addressed store, hash-verified

49}
50
51func ExpandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error) {
52 edges := make([]*pb.DirectedEdge, 0, 2*len(m.Edges))
53 namespace, err := x.ExtractNamespace(ctx)
54 if err != nil {
55 return nil, errors.Wrapf(err, "While expanding edges")
56 }
57 isGalaxyQuery := x.IsRootNsOperation(ctx)
58
59 // Reset the namespace to the original.
60 defer func(ns uint64) {
61 x.AttachNamespace(ctx, ns)
62 }(namespace)
63
64 for _, edge := range m.Edges {
65 x.AssertTrue(edge.Op == pb.DirectedEdge_DEL || edge.Op == pb.DirectedEdge_SET)
66 if isGalaxyQuery {
67 // The caller should make sure that the directed edges contain the namespace we want
68 // to insert into. Now, attach the namespace in the context, so that further query
69 // proceeds as if made from the user of 'namespace'.
70 namespace = edge.GetNamespace()
71 x.AttachNamespace(ctx, namespace)
72 }
73
74 var preds []string
75 if edge.Attr != x.Star {
76 preds = []string{x.NamespaceAttr(namespace, edge.Attr)}
77 } else {
78 sg := &SubGraph{}
79 sg.DestUIDs = &pb.List{Uids: []uint64{edge.GetEntity()}}
80 sg.ReadTs = m.StartTs
81 types, err := getNodeTypes(ctx, sg)
82 if err != nil {
83 return nil, err
84 }
85 preds = append(preds, getPredicatesFromTypes(namespace, types)...)
86 preds = append(preds, x.StarAllPredicates(namespace)...)
87 // AllowedPreds are used only with ACL. Do not delete all predicates but
88 // delete predicates to which the mutation has access
89 if edge.AllowedPreds != nil {
90 // Take intersection of preds and AllowedPreds
91 intersectPreds := make([]string, 0)
92 hashMap := make(map[string]bool)
93 for _, allowedPred := range edge.AllowedPreds {
94 hashMap[allowedPred] = true
95 }
96 for _, pred := range preds {
97 if _, found := hashMap[pred]; found {
98 intersectPreds = append(intersectPreds, pred)
99 }
100 }
101 preds = intersectPreds
102 }
103 }
104
105 for _, pred := range preds {
106 // Do not return reverse edges.
107 if x.ParseAttr(pred)[0] == '~' {
108 continue

Callers 1

ApplyMutationsFunction · 0.85

Calls 11

ExtractNamespaceFunction · 0.92
IsRootNsOperationFunction · 0.92
AttachNamespaceFunction · 0.92
AssertTrueFunction · 0.92
NamespaceAttrFunction · 0.92
StarAllPredicatesFunction · 0.92
ParseAttrFunction · 0.92
getNodeTypesFunction · 0.85
getPredicatesFromTypesFunction · 0.85
GetEntityMethod · 0.80
GetNamespaceMethod · 0.45

Tested by

no test coverage detected