I am trying to create apis for altering Dgraph nodes and predicates using go client, so my question is I can easily create an api for the create operation but if I want to update a node with a new field or to remove an existing field how can I achieve that and also if I want to change the predicate name to differentiate the type data then how can I acheive that ??
can you explain me how to achieve this in Dgraph and if possible please direct me to the right reference
so I want to get the schema and alter the name to person_name using go client
I wrote a simple go program which change the “name” to “person_name” for the schema that you provided, similarly you can do it for company_name or in general for any predicate.
import (
"context"
"log"
"google.golang.org/grpc"
"github.com/dgraph-io/dgo/v200"
"github.com/dgraph-io/dgo/v200/protos/api"
)
func main() {
conn, err := grpc.Dial("127.0.0.1:9080", grpc.WithInsecure())
if err != nil {
log.Fatal("While trying to dial gRPC")
}
dc := dgo.NewDgraphClient(api.NewDgraphClient(conn))
ctx := context.Background()
q := `
query {
user as var(func: type(Person)){
n as name
}
}`
mu := &api.Mutation{
SetNquads: []byte(`uid(user) <person_name> val(n) .`),
DelNquads: []byte(`uid(user) <name> * .`),
}
req := &api.Request{
Query: q,
Mutations: []*api.Mutation{mu},
CommitNow:true,
}
if _, err := dc.NewTxn().Do(ctx, req); err != nil {
log.Fatal(err)
}
}