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

Function ParseWithNeedVars

dql/parser.go:641–738  ·  view source on GitHub ↗

ParseWithNeedVars performs parsing of a query with given needVars. The needVars parameter is passed in the case of upsert block. For example, when parsing the query block inside - upsert { query { me(func: eq(email, "someone@gmail.com"), first: 1) { v as uid } } mutatio

(r Request, needVars []string)

Source from the content-addressed store, hash-verified

639// The variable name v needs to be passed through the needVars parameter. Otherwise, an error
640// is reported complaining that the variable v is defined but not used in the query block.
641func ParseWithNeedVars(r Request, needVars []string) (res Result, rerr error) {
642 query := r.Str
643 vmap := convertToVarMap(r.Variables)
644
645 var lexer lex.Lexer
646 lexer.Reset(query)
647 lexer.Run(lexTopLevel)
648 if err := lexer.ValidateResult(); err != nil {
649 return res, err
650 }
651
652 var qu *GraphQuery
653 it := lexer.NewIterator()
654 fmap := make(fragmentMap)
655 for it.Next() {
656 item := it.Item()
657 switch item.Typ {
658 case itemOpType:
659 switch item.Val {
660 case "mutation":
661 return res, item.Errorf("Mutation block no longer allowed.")
662 case "schema":
663 if res.Schema != nil {
664 return res, item.Errorf("Only one schema block allowed ")
665 }
666 if res.Query != nil {
667 return res, item.Errorf("Schema block is not allowed with query block")
668 }
669 if res.Schema, rerr = getSchema(it); rerr != nil {
670 return res, rerr
671 }
672 case "fragment":
673 // TODO(jchiu0): This is to be done in ParseSchema once it is ready.
674 fnode, rerr := getFragment(it)
675 if rerr != nil {
676 return res, rerr
677 }
678 fmap[fnode.Name] = fnode
679 case "query":
680 if res.Schema != nil {
681 return res, item.Errorf("Schema block is not allowed with query block")
682 }
683 if qu, rerr = getVariablesAndQuery(it, vmap); rerr != nil {
684 return res, rerr
685 }
686 res.Query = append(res.Query, qu)
687 }
688 case itemLeftCurl:
689 if qu, rerr = getQuery(it); rerr != nil {
690 return res, rerr
691 }
692 res.Query = append(res.Query, qu)
693 case itemName:
694 it.Prev()
695 if qu, rerr = getQuery(it); rerr != nil {
696 return res, rerr
697 }
698 res.Query = append(res.Query, qu)

Callers 2

parseRequestFunction · 0.92
ParseFunction · 0.85

Calls 15

ResetMethod · 0.95
RunMethod · 0.95
ValidateResultMethod · 0.95
NewIteratorMethod · 0.95
expandFragmentsMethod · 0.95
collectVarsMethod · 0.95
convertToVarMapFunction · 0.85
getFragmentFunction · 0.85
getVariablesAndQueryFunction · 0.85
getQueryFunction · 0.85
substituteVariablesFunction · 0.85
checkDependencyFunction · 0.85

Tested by

no test coverage detected