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

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

问题描述

我已经使用 Django 设置了一个石墨烯服务器.当我通过 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 {
  partners{
    name
    url
    logo
  }
}","variables":"null","operationName":"PartnersQuery"}

当我使用 Content-Type: application/json 将它复制到 Postman 时,我得到以下响应:

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())),

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

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