-
Notifications
You must be signed in to change notification settings - Fork 85
Closed
Description
Hi,
Is it possible to retrieve the query result of an upsert block? I checked the resp.Json field of the api.Response from tx.Do, it returns an empty object {}.
Here is an example code.
schema := `username: string @index(term) @upsert .
email: string @index(term) @upsert .
no: int @index(int) @upsert .
name: string @index(term) .
type User {
name
username
email
no
}`
err := c.Alter(context.Background(), &api.Operation{Schema: schema})
if err != nil {
log.Println(err)
}
query := `{
q2 as var(func: type(User)) @filter(eq(username, "wildan")) { uid }
q3 as var(func: type(User)) @filter(eq(email, "wildan2711@gmail.com")) { uid }
}`
condition := `@if(eq(len(q2), 0) AND eq(len(q3), 0))`
jsonData := `{"dgraph.type":"User","name":"H3h3","username":"wildan","email":"wildan2711@gmail.com","no":1}`
tx := c.NewTxn()
assigned, err := tx.Do(context.Background(), &api.Request{
Query: query,
Mutations: []*api.Mutation{
&api.Mutation{
Cond: conditionString,
SetJson: jsonData,
}
},
CommitNow: true,
})
log.Println(string(assigned.Json), assigned.Uids)
tx = c.NewTxn()
assigned, err = tx.Do(context.Background(), &api.Request{
Query: query,
Mutations: []*api.Mutation{
&api.Mutation{
Cond: conditionString,
SetJson: jsonData,
}
},
CommitNow: true,
})
log.Println(string(assigned.Json), assigned.Uids)Which returns:
2020/01/04 13:16:01 {} map[dg.675717852.13:0x4e27]
2020/01/04 13:16:01 {} map[]
Thanks.
Metadata
Metadata
Assignees
Labels
No labels