mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 09:57:53 +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())
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user