Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add translation query for Category

fowczarek4f9e6250812b
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index eaf7ae8a32..be324c5e3b 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -1,6 +1,6 @@
import graphene
-from ...product.models import Collection, Product
+from ...product.models import Category, Collection, Product
from ..core.connection import CountableConnection
from ..core.fields import BaseConnectionField
from ..decorators import permission_required
@@ -43,7 +43,11 @@ class TranslatableItem(graphene.Union):
# TODO Consider name of this class
class DefaultTranslationItem(graphene.Union):
class Meta:
- types = (translation_types.ProductStrings, translation_types.CollectionStrings)
+ types = (
+ translation_types.ProductStrings,
+ translation_types.CollectionStrings,
+ translation_types.CategoryStrings,
+ )
class TranslatableItemConnection(CountableConnection):
@@ -74,6 +78,7 @@ class TranslationQueries(graphene.ObjectType):
TranslatableKinds, required=True, description="Kind of objects to retrieve."
),
)
+ # TODO Add test for this query
translation = graphene.Field(
DefaultTranslationItem,
id=graphene.Argument(
@@ -117,3 +122,6 @@ class TranslationQueries(graphene.ObjectType):
elif kind == TranslatableKinds.COLLECTION:
_type, collection_id = graphene.Node.from_global_id(id)
return Collection.objects.filter(pk=collection_id).first()
+ elif kind == TranslatableKinds.CATEGORY:
+ _type, category_id = graphene.Node.from_global_id(id)
+ return Category.objects.filter(pk=category_id).first()
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index 70ae9eeea6..bf997ad2f6 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -174,6 +174,38 @@ class CategoryTranslation(BaseTranslationType):
]
+class CategoryStrings(CountableDjangoObjectType):
+ translation = graphene.Field(
+ CategoryTranslation,
+ language_code=graphene.Argument(
+ LanguageCodeEnum,
+ description="A language code to return the translation for.",
+ required=True,
+ ),
+ description=("Returns translated Category fields for the given language code."),
+ resolver=resolve_translation,
+ )
+ category = graphene.Field(
+ "saleor.graphql.product.types.products.Category",
+ description="Represents a single category of products.",
+ )
+
+ class Meta:
+ model = product_models.Category
+ interfaces = [graphene.relay.Node]
+ only_fields = [
+ "description",
+ "description_json",
+ "id",
+ "name",
+ "seo_title",
+ "seo_description",
+ ]
+
+ def resolve_category(self, info):
+ return self
+
+
class PageTranslation(BaseTranslationType):
class Meta:
model = page_models.PageTranslation