Hi!
I’m using dgraph version 1.1.0 and trying to run the following test code
package main
import (
"context"
"fmt"
"log"
"strings"
"time"
dgo "github.com/dgraph-io/dgo/v2"
"github.com/dgraph-io/dgo/v2/protos/api"
"google.golang.org/grpc"
)
const (
uidGetByName = `
query {
me(func: eq(name, "%NAME%")) {
uidValue as uid
}
}
`
mutationMsisdn = `
uid(uidValue) <name> "%MSISDN%" .
uid(uidValue) <msisdn> "%MSISDN%" .
uid(uidValue) <dateAdd> "%DATETIME%" .
uid(uidValue) <dgraph.type> "msisdn" .
`
)
var (
msisdns = []string{"1", "2", "3", "4", "5"}
)
func main() {
upserts := []*api.Request{}
for _, val := range msisdns {
mu := &api.Mutation{SetNquads: []byte(strings.Replace(strings.Replace(uidGetByName, "%MSISDN%", val, -1), "%DATETIME%", time.Now().UTC().Format(time.RFC3339), -1))}
upserts = append(
upserts,
&api.Request{
Query: strings.Replace(uidGetByName, "%NAME%", val, -1),
Mutations: []*api.Mutation{mu},
},
)
}
ctx, toCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer toCancel()
conn, err := grpc.Dial("ip:port", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
dg := dgo.NewDgraphClient(api.NewDgraphClient(conn))
txn := dg.NewTxn()
defer txn.Discard(ctx)
for _, curUpsert := range upserts {
res, err := txn.Do(ctx, curUpsert)
if err != nil {
log.Fatal(err)
}
log.Println("mutationNodesCommon answer", res.String())
fmt.Println()
}
txn.Commit(ctx)
}
but I end up getting the error:
rpc error: code = Unknown desc = while lexing query { at line 1 column 0: Invalid input: q at lexText
I’ve tried to remove “query” word and “{}” but it doesn’t help me.