Как решить проблему "Could not import 'todo.schema.schema' for Graphene setting 'SCHEMA'. AttributeError: модуль 'graphene' не имеет атрибута 'string'."?

Я создаю проект Django graphene. Вдруг получаю ошибку Could not import 'todo.schema.schema' for Graphene setting 'SCHEMA'. AttributeError: module 'graphene' has no attribute 'string'. Но я не нахожу, как ее решить.

Моя структура схемы такова: todo/schema/schema

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

main 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)

app schema.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()

Что я упустил? Или может быть я делаю что-то не так?

У вас опечатка в text = graphene.string(Required=True). В ошибке также говорится, что у графена нет строки атрибутов. Она чувствительна к регистру и должна быть text = graphene.String(Required=True) Вы можете использовать линтер для вашего редактора, чтобы вы могли отлавливать такие незначительные вещи в будущем.

Вернуться на верх