Ratel doesn't accept mutations in JSON format

Moved from GitHub ratel/220

Posted by danielmai:

Steps to reproduce

I’m trying to send the following mutation in Ratel:

{"set":[{"uid":"_:root","connects":[{"name": "A"},{"name":"B"}]]}

I get the following error, when I expect it to succeed:

{
  "name": "t",
  "url": "http://localhost:8080/mutate?commitNow=true",
  "errors": [
    {
      "message": "while lexing {\"set\":[{\"uid\":\"_:root\",\"connects\":[{\"name\": \"A\"},{\"name\":\"B\"}]]} at line 1 column 1: Unrecognized character inside mutation: U+0022 '\"'",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

This error message is telling me that the mutation was processed as an RDF mutation when it should’ve processed it as a JSON mutation. In the network inspector, I see it sent the mutation request with the Content-Type header as application/rdf instead of application/json.

Additional info

Ratel info from the Latest distribution

Built at 2020-06-17T15:16:21.698Z
Commit: 2cdc64b
Commit Info: 2cdc64b Wed Jun 17 18:15:46 2020 +0300 (HEAD -> master)

Dgraph version v20.03.3.

paulftw commented :

This is happening because query doesn’t parse as JSON so it’s sent as RDF.
If Ratel sent it as JSON there’d be a different though more relevant syntax error returned.

Correct JSON:

{"set":[{"uid":"_:root","connects":[{"name": "A"},{"name":"B"}]}]}

Incorrect JSON:

{"set":[{"uid":"_:root","connects":[{"name": "A"},{"name":"B"}]]}

Note one more curly closing bracket in the end of the correct query.

I’m closing this issue as working as expected and will file a feature request to provide a visual indication of the detected content-type.