mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-11-01 16:37:39 +03:00
* Use ruff in pre-commit * Add pyupgrade * Add isort * Add bugbear * Fix B015 Pointless comparison * Fix B026 * B018 false positive * Remove flake8 and isort config from setup.cfg * Remove black and flake8 from dev dependencies * Update black * Show list of fixes applied with autofix on * Fix typo * Add C4 flake8-comprehensions * Add ruff to dev dependencies * Fix up
35 lines
1015 B
Python
35 lines
1015 B
Python
from graphene import Node
|
|
from graphene_django.filter import DjangoFilterConnectionField
|
|
from graphene_django.types import DjangoObjectType
|
|
|
|
from cookbook.recipes.models import Recipe, RecipeIngredient
|
|
|
|
|
|
class RecipeNode(DjangoObjectType):
|
|
class Meta:
|
|
model = Recipe
|
|
interfaces = (Node,)
|
|
fields = "__all__"
|
|
filter_fields = ["title", "amounts"]
|
|
|
|
|
|
class RecipeIngredientNode(DjangoObjectType):
|
|
class Meta:
|
|
model = RecipeIngredient
|
|
# Allow for some more advanced filtering here
|
|
interfaces = (Node,)
|
|
fields = "__all__"
|
|
filter_fields = {
|
|
"ingredient__name": ["exact", "icontains", "istartswith"],
|
|
"recipe": ["exact"],
|
|
"recipe__title": ["icontains"],
|
|
}
|
|
|
|
|
|
class Query:
|
|
recipe = Node.Field(RecipeNode)
|
|
all_recipes = DjangoFilterConnectionField(RecipeNode)
|
|
|
|
recipeingredient = Node.Field(RecipeIngredientNode)
|
|
all_recipeingredients = DjangoFilterConnectionField(RecipeIngredientNode)
|