Skip to content

Commit

Permalink
Updated ingredients/schema.py and recipes/schema.py to be more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
alqinae committed Oct 18, 2018
1 parent 4359e1f commit 905b424
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
14 changes: 4 additions & 10 deletions examples/cookbook-plain/cookbook/ingredients/schema.py
Expand Up @@ -25,17 +25,14 @@ class Query(object):
name=graphene.String())
all_ingredients = graphene.List(IngredientType)

def resolve_all_categories(self, context, **kwargs):
def resolve_all_categories(self, context):
return Category.objects.all()

def resolve_all_ingredients(self, context, **kwargs):
def resolve_all_ingredients(self, context):
# We can easily optimize query count in the resolve method
return Ingredient.objects.select_related('category').all()

def resolve_category(self, context, **kwargs):
id = kwargs.get('id')
name = kwargs.get('name')

def resolve_category(self, context, id=None, name=None):
if id is not None:
return Category.objects.get(pk=id)

Expand All @@ -44,10 +41,7 @@ def resolve_category(self, context, **kwargs):

return None

def resolve_ingredient(self, context, **kwargs):
id = kwargs.get('id')
name = kwargs.get('name')

def resolve_ingredient(self, context, id=None, name=None):
if id is not None:
return Ingredient.objects.get(pk=id)

Expand Down
13 changes: 4 additions & 9 deletions examples/cookbook-plain/cookbook/recipes/schema.py
Expand Up @@ -24,10 +24,7 @@ class Query(object):
id=graphene.Int())
all_recipeingredients = graphene.List(RecipeIngredientType)

def resolve_recipe(self, context, **kwargs):
id = kwargs.get('id')
title = kwargs.get('title')

def resolve_recipe(self, context, id=None, title=None):
if id is not None:
return Recipe.objects.get(pk=id)

Expand All @@ -36,17 +33,15 @@ def resolve_recipe(self, context, **kwargs):

return None

def resolve_recipeingredient(self, context, **kwargs):
id = kwargs.get('id')

def resolve_recipeingredient(self, context, id=None):
if id is not None:
return RecipeIngredient.objects.get(pk=id)

return None

def resolve_all_recipes(self, context, **kwargs):
def resolve_all_recipes(self, context):
return Recipe.objects.all()

def resolve_all_recipeingredients(self, context, **kwargs):
def resolve_all_recipeingredients(self, context):
related = ['recipe', 'ingredient']
return RecipeIngredient.objects.select_related(*related).all()

0 comments on commit 905b424

Please sign in to comment.