From 905b4249f3ff71b35105638242c3f908ead70324 Mon Sep 17 00:00:00 2001 From: Khaled Alqenaei Date: Thu, 18 Oct 2018 12:27:23 -0700 Subject: [PATCH] Updated ingredients/schema.py and recipes/schema.py to be more readable. --- .../cookbook-plain/cookbook/ingredients/schema.py | 14 ++++---------- examples/cookbook-plain/cookbook/recipes/schema.py | 13 ++++--------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/examples/cookbook-plain/cookbook/ingredients/schema.py b/examples/cookbook-plain/cookbook/ingredients/schema.py index 51f25ed..e7ef688 100644 --- a/examples/cookbook-plain/cookbook/ingredients/schema.py +++ b/examples/cookbook-plain/cookbook/ingredients/schema.py @@ -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) @@ -44,10 +41,7 @@ class Query(object): 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) diff --git a/examples/cookbook-plain/cookbook/recipes/schema.py b/examples/cookbook-plain/cookbook/recipes/schema.py index 620d510..74692f8 100644 --- a/examples/cookbook-plain/cookbook/recipes/schema.py +++ b/examples/cookbook-plain/cookbook/recipes/schema.py @@ -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) @@ -36,17 +33,15 @@ class Query(object): 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()