Created
June 27, 2019 15:52
-
-
Save chris001177/b5dd66db07b3a6e1f90ca758df756ffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cookbook/ingredients/schema.py | |
import graphene | |
from graphene_django.types import DjangoObjectType | |
from ingredients.models import Category, Ingredient | |
class CategoryType(DjangoObjectType): | |
class Meta: | |
model = Category | |
class IngredientType(DjangoObjectType): | |
class Meta: | |
model = Ingredient | |
class Query(object): | |
all_categories = graphene.List(CategoryType) | |
all_ingredients = graphene.List(IngredientType) | |
def resolve_all_categories(self, info, **kwargs): | |
return Category.objects.all() | |
def resolve_all_ingredients(self, info, **kwargs): | |
# We can easily optimize query count in the resolve method | |
return Ingredient.objects.select_related('category').all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment