POST with `curl` returns parsing error

Greetings,

Getting to know Dgraph GraphQL by running it on a single host following the documentation available at
https://dgraph.io/docs/deploy/single-host-setup/#run-directly-on-the-host

(As a new user we were limited to 2 links in our post so wherever you see :// you’ll have to image there
is an http or https)

We have Apache2 sitting in front of Dgraph v20.07 with

ProxyPass "/dgraph"  "://0.0.0.0:8080"
ProxyPassReverse "/dgraph"  "://0.0.0.0:8080"

ProxyPass "/"  "://0.0.0.0:8000/"
ProxyPassReverse "/"  "://0.0.0.0:8000"
ProxyPass "/?latest"  "://0.0.0.0:8000/?latest"
ProxyPassReverse "/?latest"  "://0.0.0.0:8000?latest"

We can access and use the latest Ratel.
We can define and create a schema,

$ more schema.graphql
type Task {
    id: ID!
    title: String!
    completed: Boolean!
    user: User!
}

type User {
    username: String! @id
    name: String
    tasks: [Task] @hasInverse(field: user)
}
$ curl -X POST ://example.com/dgraph/admin/schema --data-binary '@schema.graphql'
{"data":{"code":"Success","message":"Done"}}

However, POSTs to ://example.com/dgraph/graphql return parsing errors.

mutation {
  addUser(input: [
    {
      username: "alice@dgraph.io",
      name: "Alice",
      tasks: [
        {
          title: "Avoid touching your face",
          completed: false,
        },
        {
          title: "Stay safe",
          completed: false
        },
        {
          title: "Avoid crowd",
          completed: true,
        },
        {
          title: "Wash your hands often",
          completed: true
        }
      ]
    }
  ]) {
    user {
      username
      name
      tasks {
        id
        title
      }
    }
  }

}
$ curl -H "Content-Type: application/json" -X POST ://example.com/dgraph/graphql --data-binary '@mutate.query'

{"errors":[{"message":"Not a valid GraphQL request body: invalid character 'm' looking for beginning of value"}]}
$ more getSchema.query
query {
  getGQLSchema {
    schema
  }
}
$ curl -H "Content-Type: application/json" -X POST ://example.com/dgraph/graphql --data-binary '@getSchema.query'
{"errors":[{"message":"Not a valid GraphQL request body: invalid character 'q' looking for beginning of value"}]}

Using GraphiQL against ://example.com/dgraph/graphql works.

What are we doing wrong?

Thank you

If you send it as JSON type, you have to send a JSON file see this docs https://dgraph.io/docs/graphql/api/requests/

Otherwise, change the type to Content-Type: application/graphql

1 Like