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

Function getVariablesAndQuery

dql/parser.go:863–895  ·  view source on GitHub ↗

getVariablesAndQuery checks if the query has a variable list and stores it in vmap. For variable list to be present, the query should have a name which is also checked for. It also calls getQuery to create the GraphQuery object tree.

(it *lex.ItemIterator, vmap varMap)

Source from the content-addressed store, hash-verified

861// vmap. For variable list to be present, the query should have a name which is
862// also checked for. It also calls getQuery to create the GraphQuery object tree.
863func getVariablesAndQuery(it *lex.ItemIterator, vmap varMap) (gq *GraphQuery, rerr error) {
864 var name string
865L2:
866 for it.Next() {
867 item := it.Item()
868 switch item.Typ {
869 case itemName:
870 if name != "" {
871 return nil, item.Errorf("Multiple word query name not allowed.")
872 }
873 name = item.Val
874 case itemLeftRound:
875 if name == "" {
876 return nil, item.Errorf("Variables can be defined only in named queries.")
877 }
878
879 if rerr = parseDqlVariables(it, vmap); rerr != nil {
880 return nil, rerr
881 }
882
883 if rerr = checkValueType(vmap); rerr != nil {
884 return nil, rerr
885 }
886 case itemLeftCurl:
887 if gq, rerr = getQuery(it); rerr != nil {
888 return nil, rerr
889 }
890 break L2
891 }
892 }
893
894 return gq, nil
895}
896
897// parseVarName returns the variable name.
898func parseVarName(it *lex.ItemIterator) (string, error) {

Callers 1

ParseWithNeedVarsFunction · 0.85

Calls 6

parseDqlVariablesFunction · 0.85
checkValueTypeFunction · 0.85
getQueryFunction · 0.85
ItemMethod · 0.80
NextMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected