From 5ac046a715cdce60abdcbbb5165ef979cabb1fe1 Mon Sep 17 00:00:00 2001 From: chriscauley Date: Thu, 3 Nov 2016 18:06:23 -0400 Subject: [PATCH] adding recipe schema --- examples/cookbook/cookbook/recipes/schema.py | 32 ++++++++++++++++++++ examples/cookbook/cookbook/schema.py | 3 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 examples/cookbook/cookbook/recipes/schema.py diff --git a/examples/cookbook/cookbook/recipes/schema.py b/examples/cookbook/cookbook/recipes/schema.py new file mode 100644 index 0000000..0eff9e4 --- /dev/null +++ b/examples/cookbook/cookbook/recipes/schema.py @@ -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) diff --git a/examples/cookbook/cookbook/schema.py b/examples/cookbook/cookbook/schema.py index 55fae16..910e259 100644 --- a/examples/cookbook/cookbook/schema.py +++ b/examples/cookbook/cookbook/schema.py @@ -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')