File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
examples/cookbook/cookbook Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 11import cookbook .ingredients .schema
2+ import cookbook .recipes .schema
23import graphene
34
45from 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
You can’t perform that action at this time.
0 commit comments