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

Function findMutationVars

edgraph/server.go:951–993  ·  view source on GitHub ↗

findMutationVars finds all the variables used in mutation block and stores them qc.uidRes and qc.valRes so that we only look for these variables in query results.

(qc *queryContext)

Source from the content-addressed store, hash-verified

949// findMutationVars finds all the variables used in mutation block and stores them
950// qc.uidRes and qc.valRes so that we only look for these variables in query results.
951func findMutationVars(qc *queryContext) []string {
952 updateVars := func(s string) {
953 if strings.HasPrefix(s, "uid(") {
954 varName := s[4 : len(s)-1]
955 qc.uidRes[varName] = nil
956 } else if strings.HasPrefix(s, "val(") {
957 varName := s[4 : len(s)-1]
958 qc.valRes[varName] = nil
959 }
960 }
961
962 for _, gmu := range qc.gmuList {
963 for _, nq := range gmu.Set {
964 updateVars(nq.Subject)
965 updateVars(nq.ObjectId)
966 }
967 for _, nq := range gmu.Del {
968 updateVars(nq.Subject)
969 updateVars(nq.ObjectId)
970 }
971 }
972
973 varsList := make([]string, 0, len(qc.uidRes)+len(qc.valRes))
974 for v := range qc.uidRes {
975 varsList = append(varsList, v)
976 }
977 for v := range qc.valRes {
978 varsList = append(varsList, v)
979 }
980
981 // We use certain variables to check uniqueness. To prevent errors related to unused
982 // variables, we explicitly add them to the 'varsList' since they are not used in the mutation.
983 for _, uniqueQueryVar := range qc.uniqueVars {
984 varsList = append(varsList, uniqueQueryVar.queryVar)
985 // If the triple contains a "val()" in objectId, we need to add
986 // one more variable to the unique query. So, we explicitly add it to the varList.
987 if uniqueQueryVar.valVar != "" {
988 varsList = append(varsList, uniqueQueryVar.valVar)
989 }
990 }
991
992 return varsList
993}
994
995// updateValInNQuads picks the val() from object and replaces it with its value
996// Assumption is that Subject can contain UID, whereas Object can contain Val

Callers 1

parseRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected