这些是我的 schmema
import graphene
from graphene import relay, ObjectType, Mutation
from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from cookbook.models import Ingredient
class IngredientType(DjangoObjectType):
class Meta:
model = Ingredient
class IngredientCreate(Mutation):
class Arguments:
name = graphene.String(required=True)
note = graphene.String(required=True)
id = graphene.ID()
ingredient = graphene.Field(IngredientType)
@classmethod
def mutate(cls, root, info, name, note, id):
ingredient = IngredientType.objects.create(
name = name,
note = note
)
return IngredientCreate(ingredient=ingredient)
class Query(graphene.ObjectType):
create_ingredient = IngredientCreate.Field()
这是我的模型。
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField()
我正在尝试从 graphql django gui 创建成分,但触发了我的语法错误
{
createIngredient(
name: 'rice cooking',
note: 'a simple note',
)
}
谁能告诉我我无法创建记录的可能原因是什么?
