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

Function newGraph

query/query.go:807–889  ·  view source on GitHub ↗

newGraph returns the SubGraph and its task query.

(ctx context.Context, gq *dql.GraphQuery)

Source from the content-addressed store, hash-verified

805
806// newGraph returns the SubGraph and its task query.
807func newGraph(ctx context.Context, gq *dql.GraphQuery) (*SubGraph, error) {
808 // This would set the Result field in SubGraph,
809 // and populate the children for attributes.
810
811 // For the root, the name to be used in result is stored in Alias, not Attr.
812 // The attr at root (if present) would stand for the source functions attr.
813 args := params{
814 Alias: gq.Alias,
815 Cascade: &CascadeArgs{Fields: gq.Cascade},
816 GetUid: isDebug(ctx),
817 IgnoreReflex: gq.IgnoreReflex,
818 IsEmpty: gq.IsEmpty,
819 Langs: gq.Langs,
820 NeedsVar: append(gq.NeedsVar[:0:0], gq.NeedsVar...),
821 Normalize: gq.Normalize,
822 Order: gq.Order,
823 ParentVars: make(map[string]varValue),
824 Recurse: gq.Recurse,
825 RecurseArgs: gq.RecurseArgs,
826 ShortestPathArgs: gq.ShortestPathArgs,
827 Var: gq.Var,
828 GroupbyAttrs: gq.GroupbyAttrs,
829 IsGroupBy: gq.IsGroupby,
830 AllowedPreds: gq.AllowedPreds,
831 }
832
833 // Remove pagination arguments from the query if @cascade is mentioned since
834 // pagination will be applied post processing the data.
835 if len(args.Cascade.Fields) > 0 {
836 args.addCascadePaginationArguments(gq)
837 }
838
839 for argk := range gq.Args {
840 if !isValidArg(argk) {
841 return nil, errors.Errorf("Invalid argument: %s", argk)
842 }
843 }
844 if err := args.fill(gq); err != nil {
845 return nil, errors.Wrapf(err, "while filling args")
846 }
847
848 sg := &SubGraph{Params: args}
849
850 if gq.Func != nil {
851 // Uid function doesnt have Attr. It just has a list of ids
852 if gq.Func.Attr != "uid" {
853 sg.Attr = gq.Func.Attr
854 } else {
855 // Disallow uid as attribute - issue#3110
856 if len(gq.Func.UID) == 0 {
857 return nil, errors.Errorf(`Argument cannot be "uid"`)
858 }
859 }
860 if !isValidFuncName(gq.Func.Name) {
861 return nil, errors.Errorf("Invalid function name: %s", gq.Func.Name)
862 }
863
864 sg.createSrcFunction(gq.Func)

Callers 1

ToSubGraphFunction · 0.85

Calls 11

fillMethod · 0.95
createSrcFunctionMethod · 0.95
populateMethod · 0.95
isDebugFunction · 0.85
isValidArgFunction · 0.85
isValidFuncNameFunction · 0.85
isUidFnWithoutVarFunction · 0.85
filterCopyFunction · 0.85
toFacetsFilterFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected