1

When I send a query with Content-Type as plain text, I keep getting a

{"errors":[{"message":"Must provide query string."}]}  

When I convert the query to a JSON object and change the content-type to json, which is painful to do tbh, it works fine. This looks like a django-graphene issue. Is there a setting I need to set to allow for plain text?

Example of the query as plain text:

curl -d "query {
  hello
}" -H "Content-Type: text/plain" "http://localhost:8000/graphql"

Example of the query as json

curl -d '{"query": "query { hello}" }' -H "Content-Type: application/json" "http://localhost:8000/graphql"

I'm registering the view like this:

path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True)))
user133688
  • 6,864
  • 3
  • 20
  • 36
  • So is the only difference between the two the `content-type` header? Or does the body look different? – Code-Apprentice Oct 04 '22 at 18:12
  • Hi! I put in an example of the queries I'm making with curl. There is a slight difference, but that's because one is JSON and the other is just plain text. Thanks! – user133688 Oct 04 '22 at 20:29
  • Thanks for the clarification. I'm not familiar with graphene-django or really with GraphQL in general. I'll look at this when I can, though. – Code-Apprentice Oct 04 '22 at 21:40
  • I have a question...Do GraphQL APIs frequently accept `content-type: text/plain` with the request body formatted similar to what you show here in your example? – Code-Apprentice Oct 04 '22 at 21:43
  • Honestly, I'm not sure. I've tested it against elixirs absinth framework, and it worked there. – user133688 Oct 05 '22 at 01:24

0 Answers0