Skip to content

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

Add translation query for attribute

fowczarekcc47ee0c139c
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index be324c5e3b..713d7912c1 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -1,6 +1,6 @@
import graphene
-from ...product.models import Category, Collection, Product
+from ...product.models import Attribute, Category, Collection, Product
from ..core.connection import CountableConnection
from ..core.fields import BaseConnectionField
from ..decorators import permission_required
@@ -47,6 +47,7 @@ class DefaultTranslationItem(graphene.Union):
translation_types.ProductStrings,
translation_types.CollectionStrings,
translation_types.CategoryStrings,
+ translation_types.AttributeStrings,
)
@@ -125,3 +126,6 @@ class TranslationQueries(graphene.ObjectType):
elif kind == TranslatableKinds.CATEGORY:
_type, category_id = graphene.Node.from_global_id(id)
return Category.objects.filter(pk=category_id).first()
+ elif kind == TranslatableKinds.ATTRIBUTE:
+ _type, attribute_id = graphene.Node.from_global_id(id)
+ return Attribute.objects.filter(pk=attribute_id).first()
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index bf997ad2f6..247a0ad8e6 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -51,6 +51,33 @@ class AttributeTranslation(BaseTranslationType):
only_fields = ["id", "name"]
+class AttributeStrings(CountableDjangoObjectType):
+ translation = graphene.Field(
+ AttributeTranslation,
+ language_code=graphene.Argument(
+ LanguageCodeEnum,
+ description="A language code to return the translation for.",
+ required=True,
+ ),
+ description=(
+ "Returns translated Attribute fields " "for the given language code."
+ ),
+ resolver=resolve_translation,
+ )
+ attribute = graphene.Field(
+ "saleor.graphql.product.types.products.Attribute",
+ description="Custom attribute of a product.",
+ )
+
+ class Meta:
+ model = product_models.Attribute
+ interfaces = [graphene.relay.Node]
+ only_fields = ["id", "name"]
+
+ def resolve_attribute(self, info):
+ return self
+
+
class ProductVariantTranslation(BaseTranslationType):
class Meta:
model = product_models.ProductVariantTranslation