【问题标题】:Retrieve GraphQL Introspection Schema as http response检索 GraphQL Introspection Schema 作为 http 响应
【发布时间】:2020-12-17 12:19:04
【问题描述】:

我可以使用 Django 管理命令 as 生成 Django Graphene introspection schema

./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.json

如何将 JSON 架构作为 HTTP 响应 从视图中返回,以便客户端能够随时查看/获取相同的内容?

【问题讨论】:

  • 使用GraphQL 然后使用REST 的独特优势是什么?
  • 在这种情况下,还是在一般情况下?
  • 是的!在这种情况下。
  • 第一:这个响应不应该被查询,它应该是原样的,因为它被一些客户用来打字(例如Apollo Client)。第二:这个响应不能用 GraphQL 提供,因为它是可逆地相互依赖的

标签: python django graphql graphene-python graphene-django


【解决方案1】:

使用Schema(...)--(GitHub)类的introspect()--(GitHub)方法

from django.http.response import JsonResponse
from tutorial.quickstart import schema


def introspection_schema(request):
    data = {"data": schema.introspect()}
    return JsonResponse(data)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-01
    • 2017-02-21
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2021-02-20
    相关资源
    最近更新 更多