Hi
#golang #dgo #go
I create a func mutate in go for mutate the RDF ,
and send argument from main to func mutate
my code :
package main
import (
"context"
"log"
"fmt"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"google.golang.org/grpc"
)
func mutate(dg *dgo.Dgraph, ctx context.Context) {
mu := &api.Mutation{
CommitNow: true,
}
p := `
_:person1 <UrlName> "mahdi999" .
_:person2 <UrlName> "ali" .
`
mu.SetNquads = []byte(p)
_, err := dg.NewTxn().Mutate(ctx, mu)
if err != nil {
log.Fatal(err)
}
resp, err := dg.NewTxn().Query(context.Background(), `{
find(func: has(UrlName)) {
UrlName
}
}`)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Response: %s\n", resp.Json)
}
func main() {
conn, err := grpc.Dial("127.0.0.1:9080", grpc.WithInsecure())
if err != nil {
log.Fatal("trying to dial gRPC")
}
defer conn.Close()
dc := api.NewDgraphClient(conn)
dg := dgo.NewDgraphClient(dc)
op := &api.Operation{} // DropAll : true
ctx := context.Background()
err = dg.Alter(ctx, op)
if err != nil {
log.Fatal(err)
}
mutate(dg , ctx)
}
But when run the go show this error :
2019/09/14 15:19:20 rpc error: code = Unknown desc = Operation must have at least one field set
exit status 1
Can you help me ?!