Support comments in Mutate commands

Moved from GitHub dgraph/5640

Posted by masonlr:

In the Mutate console, the following mutation works.

Mutation:

{
  "set": [
  	{"name": "foo"}
	]
}

Response message:

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": null,
    "uids": {
      "dg.932529826.109": "0xc3be"
    }
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 46600,
      "processing_ns": 3764100,
      "assign_timestamp_ns": 1099500,
      "total_ns": 4977500
    },
    "txn": {
      "start_ts": 70252,
      "commit_ts": 70253,
      "preds": [
        "1-name"
      ]
    }
  }
}

When comments are added, an error is returned. For example:

Mutation:

{
  "set": [
  	{"name": "outer"}
	]
}

# foo

Response:

{
  "name": "t",
  "url": "http://localhost:8080/mutate?commitNow=true",
  "errors": [
    {
      "message": "while lexing {\n  \"set\": [\n  \t{\"name\": \"outer\"}\n\t]\n}\n\n# foo at line 2 column 2: Unrecognized character inside mutation: U+0022 '\"'",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

OmarAyo commented :

Hi @masonlr,

You should be able to add a comment by using rdf format. I am looking why with JSON it’s not working

{
  set {
    _:person <name> "outer" .
  }
}
#foo

OmarAyo commented :

Hi @masonlr

So if you use JSON style for mutation, comments are not allowed in JSON.
On the other hand, if you use graphql±, comments should be allowed

MichelDiz commented :

Actually, if you prefer, you can comment using JSON keys outside the scope of the mutation. Dgraph will simply ignore any key other than “set” or “delete”.

{
  "set": [
  	{"name": "foo"}
    ],
  "COMMENT": "this iss a comment",
  "//COMMENT": "this iss a comment",
  "#COMMENT": "this iss a comment"
}
2 Likes

The intended usecase was to quickly comment and uncomment blocks of code in the Mutate tab of the Ratel UI. This is handy when testing or exploring Dgraph syntax/features.

If comments aren’t stripped by the UI before being forwarded to Alpha, I suggest removing the shortcut [cmd|ctrl]+/ from the UI, i.e. as a user I thought that mutate comments would work, because the comment shortcut was supported in the Mutate tab of the UI.