mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-16 19:40:36 +03:00
Updated ingredients/schema.py and recipes/schema.py to be more readable.
This commit is contained in:
parent
4359e1f312
commit
905b4249f3
|
@ -25,17 +25,14 @@ class Query(object):
|
||||||
name=graphene.String())
|
name=graphene.String())
|
||||||
all_ingredients = graphene.List(IngredientType)
|
all_ingredients = graphene.List(IngredientType)
|
||||||
|
|
||||||
def resolve_all_categories(self, context, **kwargs):
|
def resolve_all_categories(self, context):
|
||||||
return Category.objects.all()
|
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
|
# We can easily optimize query count in the resolve method
|
||||||
return Ingredient.objects.select_related('category').all()
|
return Ingredient.objects.select_related('category').all()
|
||||||
|
|
||||||
def resolve_category(self, context, **kwargs):
|
def resolve_category(self, context, id=None, name=None):
|
||||||
id = kwargs.get('id')
|
|
||||||
name = kwargs.get('name')
|
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return Category.objects.get(pk=id)
|
return Category.objects.get(pk=id)
|
||||||
|
|
||||||
|
@ -44,10 +41,7 @@ class Query(object):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve_ingredient(self, context, **kwargs):
|
def resolve_ingredient(self, context, id=None, name=None):
|
||||||
id = kwargs.get('id')
|
|
||||||
name = kwargs.get('name')
|
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return Ingredient.objects.get(pk=id)
|
return Ingredient.objects.get(pk=id)
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,7 @@ class Query(object):
|
||||||
id=graphene.Int())
|
id=graphene.Int())
|
||||||
all_recipeingredients = graphene.List(RecipeIngredientType)
|
all_recipeingredients = graphene.List(RecipeIngredientType)
|
||||||
|
|
||||||
def resolve_recipe(self, context, **kwargs):
|
def resolve_recipe(self, context, id=None, title=None):
|
||||||
id = kwargs.get('id')
|
|
||||||
title = kwargs.get('title')
|
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return Recipe.objects.get(pk=id)
|
return Recipe.objects.get(pk=id)
|
||||||
|
|
||||||
|
@ -36,17 +33,15 @@ class Query(object):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve_recipeingredient(self, context, **kwargs):
|
def resolve_recipeingredient(self, context, id=None):
|
||||||
id = kwargs.get('id')
|
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return RecipeIngredient.objects.get(pk=id)
|
return RecipeIngredient.objects.get(pk=id)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve_all_recipes(self, context, **kwargs):
|
def resolve_all_recipes(self, context):
|
||||||
return Recipe.objects.all()
|
return Recipe.objects.all()
|
||||||
|
|
||||||
def resolve_all_recipeingredients(self, context, **kwargs):
|
def resolve_all_recipeingredients(self, context):
|
||||||
related = ['recipe', 'ingredient']
|
related = ['recipe', 'ingredient']
|
||||||
return RecipeIngredient.objects.select_related(*related).all()
|
return RecipeIngredient.objects.select_related(*related).all()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user