石墨烯Django“必须提供查询字符串” [英] Graphene Django "Must provide query string"

查看:106
本文介绍了石墨烯Django“必须提供查询字符串”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Django设置了Graphene服务器。当我通过GraphiQL(Web客户端)运行查询时,一切正常。但是,当我从其他任何地方运行时,都会出现错误:必须提供查询字符串。

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."

我进行了一些故障排除。 GraphiQL使用 Content-Type:application / json 将POST数据发送到GraphQL服务器。这是我从Chrome的网络标签复制的GraphiQL请求的正文:

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"}

当我使用 Content-Type:application / json 将其复制到邮递员时,我得到以下响应:

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?

推荐答案

签出示例应用程序,看看它们是如何工作的,

Checkout sample apps and see how they do things,

例如
https://github.com/mjtamlyn/graphene-tutorial
他们执行以下操作:

e.g. https://github.com/mjtamlyn/graphene-tutorial they do the following:

from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView

url(r'^explore', GraphQLView.as_view(graphiql=True)),
url(r'^graphql', csrf_exempt(GraphQLView.as_view())),

这篇关于石墨烯Django“必须提供查询字符串”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆