-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
356 additions
and
148 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,55 @@ | ||
import graphene | ||
import graphene | ||
|
||
from graphene_django.types import DjangoObjectType | ||
from graphene_django.types import DjangoObjectType | ||
|
||
from cookbook.ingredients.models import Category, Ingredient | ||
from cookbook.ingredients.models import Category, Ingredient | ||
|
||
|
||
class CategoryType(DjangoObjectType): | ||
class Meta: | ||
model = Category | ||
class CategoryType(DjangoObjectType): | ||
class Meta: | ||
model = Category | ||
|
||
|
||
class IngredientType(DjangoObjectType): | ||
class Meta: | ||
model = Ingredient | ||
class IngredientType(DjangoObjectType): | ||
class Meta: | ||
model = Ingredient | ||
|
||
|
||
class Query(object): | ||
category = graphene.Field(CategoryType, | ||
id=graphene.Int(), | ||
name=graphene.String()) | ||
all_categories = graphene.List(CategoryType) | ||
class Query(object): | ||
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String()) | ||
all_categories = graphene.List(CategoryType) | ||
|
||
ingredient = graphene.Field( | ||
IngredientType, id=graphene.Int(), name=graphene.String() | ||
) | ||
all_ingredients = graphene.List(IngredientType) | ||
|
||
ingredient = graphene.Field(IngredientType, | ||
id=graphene.Int(), | ||
name=graphene.String()) | ||
all_ingredients = graphene.List(IngredientType) | ||
def resolve_all_categories(self, info, **kwargs): | ||
return Category.objects.all() | ||
|
||
def resolve_all_categories(self, info, **kwargs): | ||
return Category.objects.all() | ||
def resolve_all_ingredients(self, info, **kwargs): | ||
return Ingredient.objects.all() | ||
|
||
def resolve_all_ingredients(self, info, **kwargs): | ||
return Ingredient.objects.all() | ||
def resolve_category(self, info, **kwargs): | ||
id = kwargs.get("id") | ||
name = kwargs.get("name") | ||
|
||
def resolve_category(self, info, **kwargs): | ||
id = kwargs.get('id') | ||
name = kwargs.get('name') | ||
if id is not None: | ||
return Category.objects.get(pk=id) | ||
|
||
if id is not None: | ||
return Category.objects.get(pk=id) | ||
if name is not None: | ||
return Category.objects.get(name=name) | ||
|
||
if name is not None: | ||
return Category.objects.get(name=name) | ||
return None | ||
|
||
return None | ||
def resolve_ingredient(self, info, **kwargs): | ||
id = kwargs.get("id") | ||
name = kwargs.get("name") | ||
|
||
def resolve_ingredient(self, info, **kwargs): | ||
id = kwargs.get('id') | ||
name = kwargs.get('name') | ||
if id is not None: | ||
return Ingredient.objects.get(pk=id) | ||
|
||
if id is not None: | ||
return Ingredient.objects.get(pk=id) | ||
if name is not None: | ||
return Ingredient.objects.get(name=name) | ||
|
||
if name is not None: | ||
return Ingredient.objects.get(name=name) | ||
|
||
return None | ||
return None |
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
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
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
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
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
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
Oops, something went wrong.