adding recipe schema

This commit is contained in:
chriscauley 2016-11-03 18:06:23 -04:00
parent d3057cd9dc
commit 5ac046a715
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,32 @@
from cookbook.recipes.models import Recipe, RecipeIngredient
from graphene import AbstractType, Node
from graphene_django.filter import DjangoFilterConnectionField
from graphene_django.types import DjangoObjectType
class RecipeNode(DjangoObjectType):
class Meta:
model = Recipe
interfaces = (Node, )
filter_fields = ['title','amounts']
filter_order_by = ['title']
class RecipeIngredientNode(DjangoObjectType):
class Meta:
model = RecipeIngredient
# Allow for some more advanced filtering here
interfaces = (Node, )
filter_fields = {
'ingredient__name': ['exact', 'icontains', 'istartswith'],
'recipe': ['exact'],
'recipe__name': ['icontains'],
}
filter_order_by = ['ingredient__name', 'recipe__name',]
class Query(AbstractType):
recipe = Node.Field(RecipeNode)
all_recipes = DjangoFilterConnectionField(RecipeNode)
recipeingredient = Node.Field(RecipeIngredientNode)
all_recipeingredients = DjangoFilterConnectionField(RecipeIngredientNode)

View File

@ -1,10 +1,11 @@
import cookbook.ingredients.schema
import cookbook.recipes.schema
import graphene
from graphene_django.debug import DjangoDebug
class Query(cookbook.ingredients.schema.Query, graphene.ObjectType):
class Query(cookbook.recipes.schema.Query, cookbook.ingredients.schema.Query, graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name='__debug')