【发布时间】:2021-12-03 00:37:18
【问题描述】:
我有一个带有 GraphQL 路由的 Django API。
这是我的models.py:
class MyBook(models.Model):
id = models.BigAutoField(primary_key= True)
book_name = models.CharField(max_length= 200)
title = models.CharField(max_length= 200)
在我的 Schema.py 中:
import graphene
from graphene_django.views import GraphQLSchema
from graphene_django import DjangoObjectType
from publishing_house_app.models import *
class BookType(DjangoObjectType):
class Meta:
model= MyBook
fields= "__all__"
class RootQuery(graphene.ObjectType):
books = graphene.List(BookType)
def resolve_books(self, root, info, **kwargs):
MyBook.objects.all()
MyBookSchema = graphene.Schema(query= RootQuery)
在 urls.py 中:
from .views import *
from rest_framework.urlpatterns import path
from graphene_django.views import GraphQLView
from .GraphQL import Schema
urlpatterns = [
path("graphql/", GraphQLView.as_view(graphiql= True, schema= Schema)),
]
我收到以下错误:
init 中的文件“C:\Python39\lib\site-packages\graphene_django\views.py”,第 127 行 断言是实例。 /graphql/ 处的断言错误 需要向 GraphQLView 提供 Schema。
【问题讨论】:
标签: python django django-rest-framework graphene-python graphene-django