mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-05-23 14:59:17 +03:00
* Update travis and tox * Use xenial distribution * Don't install coveralls twice * Add black and flake8 tox commands * Remove Python 3.5 test for Django master * Fix indent * Ignore migrations * Remove black for now * Run black formatting (#668) * Run black format * Update makefile * Add black to travis build
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from cookbook.ingredients.models import Category, Ingredient
|
|
from graphene import Node
|
|
from graphene_django.filter import DjangoFilterConnectionField
|
|
from graphene_django.types import DjangoObjectType
|
|
|
|
|
|
# Graphene will automatically map the Category model's fields onto the CategoryNode.
|
|
# This is configured in the CategoryNode's Meta class (as you can see below)
|
|
class CategoryNode(DjangoObjectType):
|
|
class Meta:
|
|
model = Category
|
|
interfaces = (Node,)
|
|
filter_fields = ["name", "ingredients"]
|
|
|
|
|
|
class IngredientNode(DjangoObjectType):
|
|
class Meta:
|
|
model = Ingredient
|
|
# Allow for some more advanced filtering here
|
|
interfaces = (Node,)
|
|
filter_fields = {
|
|
"name": ["exact", "icontains", "istartswith"],
|
|
"notes": ["exact", "icontains"],
|
|
"category": ["exact"],
|
|
"category__name": ["exact"],
|
|
}
|
|
|
|
|
|
class Query(object):
|
|
category = Node.Field(CategoryNode)
|
|
all_categories = DjangoFilterConnectionField(CategoryNode)
|
|
|
|
ingredient = Node.Field(IngredientNode)
|
|
all_ingredients = DjangoFilterConnectionField(IngredientNode)
|