These are my 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()
and this is my models.
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField()
I am trying to create Ingredient from graphql django gui but fires me syntax error
{
createIngredient(
name: 'rice cooking',
note: 'a simple note',
)
}
Can anyone tell me please what is the possible reasone that i cant create a record?
In graphql, you need to use double quotes for string values, not single quotes. So, if you do this, everything should work: