mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-18 04:20:34 +03:00
adding recipe schema
This commit is contained in:
parent
d3057cd9dc
commit
5ac046a715
32
examples/cookbook/cookbook/recipes/schema.py
Normal file
32
examples/cookbook/cookbook/recipes/schema.py
Normal 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)
|
|
@ -1,10 +1,11 @@
|
||||||
import cookbook.ingredients.schema
|
import cookbook.ingredients.schema
|
||||||
|
import cookbook.recipes.schema
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from graphene_django.debug import DjangoDebug
|
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')
|
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user