MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / treeCopy

Function treeCopy

query/query.go:529–661  ·  view source on GitHub ↗
(gq *dql.GraphQuery, sg *SubGraph)

Source from the content-addressed store, hash-verified

527}
528
529func treeCopy(gq *dql.GraphQuery, sg *SubGraph) error {
530 // Typically you act on the current node, and leave recursion to deal with
531 // children. But, in this case, we don't want to muck with the current
532 // node, because of the way we're dealing with the root node.
533 // So, we work on the children, and then recurse for grand children.
534 attrsSeen := make(map[string]struct{})
535
536 for _, gchild := range gq.Children {
537 if sg.Params.Alias == "shortest" && gchild.Expand != "" {
538 return errors.Errorf("expand() not allowed inside shortest")
539 }
540
541 key := ""
542 if gchild.Alias != "" {
543 key = gchild.Alias
544 } else {
545 key = uniqueKey(gchild)
546 }
547 if _, ok := attrsSeen[key]; ok {
548 return errors.Errorf("%s not allowed multiple times in same sub-query.",
549 key)
550 }
551 attrsSeen[key] = struct{}{}
552
553 args := params{
554 Alias: gchild.Alias,
555 Expand: gchild.Expand,
556 Facet: gchild.Facets,
557 FacetsOrder: gchild.FacetsOrder,
558 FacetVar: gchild.FacetVar,
559 GetUid: sg.Params.GetUid,
560 IgnoreReflex: sg.Params.IgnoreReflex,
561 Langs: gchild.Langs,
562 NeedsVar: append(gchild.NeedsVar[:0:0], gchild.NeedsVar...),
563 Normalize: gchild.Normalize || sg.Params.Normalize,
564 Order: gchild.Order,
565 Var: gchild.Var,
566 GroupbyAttrs: gchild.GroupbyAttrs,
567 IsGroupBy: gchild.IsGroupby,
568 IsInternal: gchild.IsInternal,
569 Cascade: &CascadeArgs{},
570 }
571
572 // Inherit from the parent.
573 if len(sg.Params.Cascade.Fields) > 0 {
574 args.Cascade.Fields = append(args.Cascade.Fields, sg.Params.Cascade.Fields...)
575 }
576 // Allow over-riding at this level.
577 if len(gchild.Cascade) > 0 {
578 args.Cascade.Fields = gchild.Cascade
579 }
580
581 // Remove pagination arguments from the query if @cascade is mentioned since
582 // pagination will be applied post processing the data.
583 if len(args.Cascade.Fields) > 0 {
584 args.addCascadePaginationArguments(gchild)
585 }
586

Callers 1

ToSubGraphFunction · 0.85

Calls 11

fillMethod · 0.95
createSrcFunctionMethod · 0.95
isValidArgFunction · 0.85
mathCopyFunction · 0.85
filterCopyFunction · 0.85
toFacetsFilterFunction · 0.85
IsAggregatorMethod · 0.80
IsPasswordVerifierMethod · 0.80
uniqueKeyFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected