Skip to content
Snippets Groups Projects
Commit 160e1bfd authored by Manish R Jain's avatar Manish R Jain
Browse files

Add a mutation handler function in server/main.go

parent a477eed5
No related branches found
No related tags found
No related merge requests found
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
package main package main
import ( import (
"bufio"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"runtime" "runtime"
"strings"
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
...@@ -29,6 +31,7 @@ import ( ...@@ -29,6 +31,7 @@ import (
"github.com/dgraph-io/dgraph/gql" "github.com/dgraph-io/dgraph/gql"
"github.com/dgraph-io/dgraph/posting" "github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/query" "github.com/dgraph-io/dgraph/query"
"github.com/dgraph-io/dgraph/rdf"
"github.com/dgraph-io/dgraph/store" "github.com/dgraph-io/dgraph/store"
"github.com/dgraph-io/dgraph/uid" "github.com/dgraph-io/dgraph/uid"
"github.com/dgraph-io/dgraph/worker" "github.com/dgraph-io/dgraph/worker"
...@@ -53,6 +56,24 @@ func addCorsHeaders(w http.ResponseWriter) { ...@@ -53,6 +56,24 @@ func addCorsHeaders(w http.ResponseWriter) {
w.Header().Set("Connection", "close") 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 { func queryHandler(ps *store.Store) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
addCorsHeaders(w) addCorsHeaders(w)
...@@ -75,12 +96,14 @@ func queryHandler(ps *store.Store) http.HandlerFunc { ...@@ -75,12 +96,14 @@ func queryHandler(ps *store.Store) http.HandlerFunc {
} }
glog.WithField("q", string(q)).Debug("Query received.") glog.WithField("q", string(q)).Debug("Query received.")
gq, _, err := gql.Parse(string(q)) gq, mu, err := gql.Parse(string(q))
if err != nil { if err != nil {
x.Err(glog, err).Error("While parsing query") x.Err(glog, err).Error("While parsing query")
x.SetStatus(w, x.E_INVALID_REQUEST, err.Error()) x.SetStatus(w, x.E_INVALID_REQUEST, err.Error())
return return
} }
mutationHandler(mu)
sg, err := query.ToSubGraph(gq, ps) sg, err := query.ToSubGraph(gq, ps)
if err != nil { if err != nil {
x.Err(glog, err).Error("While conversion to internal format") x.Err(glog, err).Error("While conversion to internal format")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment