Skip to content

Commit 5ac046a

Browse files
committed
adding recipe schema
1 parent d3057cd commit 5ac046a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from cookbook.recipes.models import Recipe, RecipeIngredient
2+
from graphene import AbstractType, Node
3+
from graphene_django.filter import DjangoFilterConnectionField
4+
from graphene_django.types import DjangoObjectType
5+
6+
class RecipeNode(DjangoObjectType):
7+
8+
class Meta:
9+
model = Recipe
10+
interfaces = (Node, )
11+
filter_fields = ['title','amounts']
12+
filter_order_by = ['title']
13+
14+
class RecipeIngredientNode(DjangoObjectType):
15+
16+
class Meta:
17+
model = RecipeIngredient
18+
# Allow for some more advanced filtering here
19+
interfaces = (Node, )
20+
filter_fields = {
21+
'ingredient__name': ['exact', 'icontains', 'istartswith'],
22+
'recipe': ['exact'],
23+
'recipe__name': ['icontains'],
24+
}
25+
filter_order_by = ['ingredient__name', 'recipe__name',]
26+
27+
class Query(AbstractType):
28+
recipe = Node.Field(RecipeNode)
29+
all_recipes = DjangoFilterConnectionField(RecipeNode)
30+
31+
recipeingredient = Node.Field(RecipeIngredientNode)
32+
all_recipeingredients = DjangoFilterConnectionField(RecipeIngredientNode)

examples/cookbook/cookbook/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import cookbook.ingredients.schema
2+
import cookbook.recipes.schema
23
import graphene
34

45
from graphene_django.debug import DjangoDebug
56

67

7-
class Query(cookbook.ingredients.schema.Query, graphene.ObjectType):
8+
class Query(cookbook.recipes.schema.Query, cookbook.ingredients.schema.Query, graphene.ObjectType):
89
debug = graphene.Field(DjangoDebug, name='__debug')
910

1011

0 commit comments

Comments
 (0)