首先我直接复制了官方的代码,就是这段
import graphene
from graphene_django import DjangoObjectType
from .models import Question
class QuestionType(DjangoObjectType)
class Meta:
model = Question
class QuestionMutation(graphene.Mutation)
class Arguments
# The input arguments for this mutation
text = graphene.String(required=True)
id = graphene.ID()
# The class attributes define the response of the mutation
question = graphene.Field(QuestionType)
@classmethod
def mutate(cls, root, info, text, id)
question = Question.objects.get(pk=id)
question.text = text
question.save()
# Notice we return an instance of this mutation
return QuestionMutation(question=question)
class Mutation(graphene.ObjectType):
update_question = QuestionMutation.Field()
然后在这一部分return QuestionMutation(question=question)里面的question=question报意外实参。有人知道是为什么吗?
我是运行在pycharm上,然后python版本3.13,graphene-django 3.2.3
官网代码的地址:https://docs.graphene-python.org/projects/django/en/latest/mutations/