add DjangoFormMutation to cookbook example

This commit is contained in:
Jason Kraus 2019-03-28 11:12:02 -07:00
parent 917851bd97
commit 675a989c7c
3 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,15 @@
from django import forms
from cookbook.ingredients.models import Category, Ingredient
class CategoryForm(forms.ModelForm):
class Meta:
model = Category
exclude = []
class IngredientForm(forms.ModelForm):
class Meta:
model = Ingredient
exclude = []

View File

@ -1,7 +1,9 @@
import graphene
from graphene_django.types import DjangoObjectType
from graphene_django.forms.mutation import DjangoFormMutation
from .models import Category, Ingredient
from .forms import CategoryForm, IngredientForm
class CategoryType(DjangoObjectType):
@ -49,3 +51,18 @@ class Query(object):
return Ingredient.objects.get(name=name)
return None
class CategoryMutation(DjangoFormMutation):
class Meta:
form_class = CategoryForm
class IngredientMutation(DjangoFormMutation):
class Meta:
form_class = IngredientForm
class Mutation(object):
category = CategoryMutation.Field()
ingredient = IngredientMutation.Field()

View File

@ -11,4 +11,9 @@ class Query(cookbook.ingredients.schema.Query,
debug = graphene.Field(DjangoDebug, name='__debug')
schema = graphene.Schema(query=Query)
class Mutation(cookbook.ingredients.schema.Mutation,
graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)