Graphene Django “Must provide query string”

2019-02-20 03:01发布

I have setup a Graphene server using Django. When I run my queries through GraphiQL (the web client), everything works fine. However, when I run from anywhere else, I get the error: "Must provide query string."

I did some troubleshooting. GraphiQL sends POST data to the GraphQL server with Content-Type: application/json. Here is the body of the request that I copied from Chrome network tab for GraphiQL:

{"query":"query PartnersQuery {\n  partners{\n    name\n    url\n    logo\n  }\n}","variables":"null","operationName":"PartnersQuery"}

When I copy it to Postman with Content-Type: application/json, I get the following response:

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

What can be the cause of this problem? I have not done anything crazy with the schema. Just followed the tutorials from graphene's docs. What else can cause an issue like this?

7条回答
Luminary・发光体
2楼-- · 2019-02-20 03:57

The problem in my code was that I had the URL improperly setup for graphQL. I had the following:

url(r'^graphql/', GraphQLView.as_view())

The forward slash was a huge difference. Removing it fixed the problem. The proper way to do it would be:

url(r'^graphql', GraphQLView.as_view())
查看更多
登录 后发表回答