When running an upsert operation with 1 mutation or more, each having conditions, is there a way to know if a mutation has been successfully executed or not ?
MichelDiz
(Michel Diz)
September 8, 2020, 5:07pm
2
In the body result you have few keys that might help you.
{
"data": {
"q": [],
"code": "Success",
"message": "Done",
"uids": {
"uid(v)": "0x1"
}
},
"extensions": {...}
}
If it creates a new node, the UID from it will appear in the "uids"
key.
If it just upsert, it will appear in the "q"
key (this key is your query). And the "uids"
key will be empty.
Make sure that you don’t use var block in the main query that you need information.
I have some tickets opened about implementing better contextual information about the Upsert Block. But for now, that’s what you got.
Cheers.
I don’t recognize this response format, how do you obtain it ?
n.b I work primarily with the nodejs client
MichelDiz
(Michel Diz)
September 8, 2020, 5:23pm
4
My guess (I can look later) is:
const response = await txn.mutate(mu);
await txn.commit();
console.log(response);
The api is a bit different, you can do response.getUidsMap()
to get assigned uid to new nodes and response.getJson()
will give you the payload of the query(ies) you ran.
But re-reading your original reply, I realize that you were referring to the data produce by the two functions I mentioned. And as such what you describe is what I’m already doing.
It gets complicated when performing upserts on multiple entities within the same operation however.
Thanks for your reply anyways
Any chance you could link to some of those tickets, so that I could track the advancement ?
MichelDiz
(Michel Diz)
September 8, 2020, 6:53pm
6
This one
https://github.com/dgraph-io/dgraph/issues/4048
Closed in favor of Support return response after the Upsert Block done. (Like GraphQL does) · Issue #4653 · dgraph-io/dgraph · GitHub
Which is Support return response after the Upsert Block done. (Like GraphQL does)
And this one
opened 05:44PM - 27 Apr 20 UTC
kind/enhancement
status/accepted
area/usability
area/upsert
dgraph
## Experience Report
> This could be useful to create error UI instead of a J… SON response.
### What you wanted to do
An upsert mutation.
The error model we currently have can be bad to read when making big queries. There are users (mainly customers) who make huge queries with many variables. The error message can get big and confusing. In addition to containing characters that hinder reading.
### What you actually did
A wrong upsert block
```
upsert {
query {
me(func: eq(email, "user@company1.io")) {
u as uid
n as name
a as age
e as email
}
}
mutation @if(eq(n, "Animesh")) {
set {
_:newNode <name> val(name) .
_:newNode <age> val(age) .
_:newNode <email> val(email) .
}
}
}
```
### Why that wasn't great, with examples
##### This error is bad for some cases.
```
{
"name": "t",
"url": "http://localhost:8080/mutate?commitNow=true",
"errors": [
{
"message": "Some variables are defined but not used\nDefined:[__dgraph__0 a e n u]\nUsed:[__dgraph__0 age email name]\n",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
```
#### The answer should be something like
```
{
"name": "t",
"url": "http://localhost:8080/mutate?commitNow=true",
"errors": [
{
"message": "Some variables are defined but not used",
"Defined": "a e n u",
"Used": "age email name",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
```
Or something similar to
```
{
"name": "t",
"url": "http://localhost:8080/mutate?commitNow=true",
"errors": [
{
"message": "Some variables are defined but not use",
"Details": {
"Defined": "a e n u",
"Used": "age email name"
},
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
```
Which is
Moved from GitHub dgraph/5303
Posted by MichelDiz :
Experience Report
This could be useful to create error UI instead of a JSON response.
What you wanted to do
An upsert mutation.
The error model we currently have can be bad to read when making big queries. There are users (mainly customers) who make huge queries with many variables. The error message can get big and confusing. In addition to containing characters that hinder reading.
What you actually did
A wrong upsert block
upsert {
…
1 Like
chewxy
(chewxy)
September 8, 2020, 7:04pm
7
This is what you would get out of Ratel. Your client library may already abstract away the things.
1 Like