diff --git a/server/main.go b/server/main.go index 86e2d765295002003af3964bae276f2dd2ee92c6..b3eeec0c4aeb08f60ab089d9e0cf99cd701c73c1 100644 --- a/server/main.go +++ b/server/main.go @@ -17,11 +17,13 @@ package main import ( + "bufio" "flag" "fmt" "io/ioutil" "net/http" "runtime" + "strings" "time" "github.com/Sirupsen/logrus" @@ -29,6 +31,7 @@ import ( "github.com/dgraph-io/dgraph/gql" "github.com/dgraph-io/dgraph/posting" "github.com/dgraph-io/dgraph/query" + "github.com/dgraph-io/dgraph/rdf" "github.com/dgraph-io/dgraph/store" "github.com/dgraph-io/dgraph/uid" "github.com/dgraph-io/dgraph/worker" @@ -53,6 +56,24 @@ func addCorsHeaders(w http.ResponseWriter) { w.Header().Set("Connection", "close") } +func mutationHandler(mu *gql.Mutation) error { + r := strings.NewReader(mu.Set) + scanner := bufio.NewScanner(r) + for scanner.Scan() { + ln := strings.Trim(scanner.Text(), " \t") + if len(ln) == 0 { + continue + } + nq, err := rdf.Parse(ln) + if err != nil { + glog.WithError(err).Error("While parsing RDF.") + return err + } + _ = nq + } + return nil +} + func queryHandler(ps *store.Store) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { addCorsHeaders(w) @@ -75,12 +96,14 @@ func queryHandler(ps *store.Store) http.HandlerFunc { } glog.WithField("q", string(q)).Debug("Query received.") - gq, _, err := gql.Parse(string(q)) + gq, mu, err := gql.Parse(string(q)) if err != nil { x.Err(glog, err).Error("While parsing query") x.SetStatus(w, x.E_INVALID_REQUEST, err.Error()) return } + mutationHandler(mu) + sg, err := query.ToSubGraph(gq, ps) if err != nil { x.Err(glog, err).Error("While conversion to internal format")