【发布时间】:2021-11-10 03:06:14
【问题描述】:
我创建了 Django 石墨烯项目。突然我收到一个错误无法为石墨烯设置“SCHEMA”导入“todo.schema.schema”。 AttributeError: module 'graphene' has no attribute 'string'。但我不知道如何解决。
我的架构结构是: 待办事项/模式/模式
seting.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# third party app
'graphene_django',
'django_filters',
]
GRAPHENE = {
'SCHEMA': 'todo.schema.schema'
}
主 urls.py:
urlpatterns = [
path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
schema.py:
class Query(TodoQuery, graphene.ObjectType):
pass
class Mutation(Mutation, graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)
应用架构.py:
# declar todo model field
class TodoType(DjangoObjectType):
class Meta:
model = TodoList
fields = ('id', 'title', 'date', 'text')
# declar user model filed
class UserType(DjangoObjectType):
class Meta:
model = User
# todo list query
class TodoQuery(graphene.ObjectType):
todoList = DjangoListField(TodoType)
def resolve_todoList(root, info):
return TodoList.objects.filter(userId=2)
# create todo
class TodoCreate(graphene.Mutation):
class Arguments:
title = graphene.String(Required=True)
text = graphene.string(Required=True)
todo = graphene.Field(TodoType)
def mutate(root, info, title, text):
# userId = info.context.user
user = User.objects.get(id=2)
todo = TodoList(userId=user, title=title, text=text)
todo.save()
return TodoCreate(todo=todo)
# todo mutation
class Mutation(graphene.ObjectType):
createTodo = TodoCreate.Field()
我错过了什么?还是我做错了什么?
【问题讨论】:
标签: python python-3.x django graphene-python graphene-django