How to obtain success message from conditional upsert using Dgraph JS gRPC client?

Hi, after completed a conditional upsert using the Dgraph JS gRPC client, is it possible to get a response on whether the mutation was committed? There are 2 possible outcomes: 1. conditions not fulfilled so no commit. 2. conditions are fulfilled so commit the transaction. I am trying to distinguish these 2 outcomes. I tried getJson(), getMetrics(), …etc but I was not able to figure out how to check the status of the transaction after it was completed by the Dgraph db.

Please, share your query so I can check it and show what is missing.

Here is my query:

upsert{
query {
    tree as var( func: uid(0xabc11) )
    {
      defects:~parent_tree @filter(type(Defect))
      {
          d as uid
      }              
    }

    var(func: uid($uid))
    {
      child_tree: ~parent_tree @filter(type(Tree))
      {
          ct as uid
      }              
    }
  }

mutate @if( eq( len(d), 0) AND eq( len(ct), 0) ){
     delete {
         uid(tree) * *.
     }
}
}

I like to get a confirmation message that the tree is delete from the client. However I am not able to do so. For example, when it fails the conditions and do not delete, the message i receive is still “success”.

Thanks for sharing it. I gonna answer in parts.

Take this query as an example

The main point to get the right responses from Dgraph, is to never use “var” block if you wanna see what you are doing.

upsert {
  query {
    q(func: eq(email, "user@company1.io")) {
      v as uid
    }
  }

  mutation {
    set {
      uid(v) <email> "user@company1.io" .
      uid(v) <age> "28" .
    }
  }
}

The first time you run it you will get this answer.

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": []
    },
    "uids": {
      "uid(v)": "0x4e22"
    }
  }
}

As you can see, the “uids” field indicates that we have created a new node and it returns us a UID in the “uid (v)” key.

If you run the same query again, it gonna return this

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": [
        {
          "uid": "0x4e22"
        }
      ]
    },
    "uids": {}
  }
}

As you can see, the “uids” field is empty and now we have a response in the “queries” field. This indicates that a new node was not created. “0x4e22” is the node that has the email “user@company1.io”.

For now, that’s the behavior you have to pay attention to.

See this issue to understand what happened in that context.

Also, follow this

I’d like to further add to clarify.

The conditional mutation may or may not have been executed depending on the “if” condition being satisfied. Both these are valid “successful” outcomes of the Upsert. Expecting an error when the condition is not met is incorrect assumption.

Oic. Thanks for your reply.

Ok. so it’s an open issue. Thanks for your help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.