Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Separate parent from category input
akjanik4bce7d7eb201
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 867f68e8e8..ed89ace974 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -11,17 +11,14 @@ from ...core.types.money import TaxRateTypefrom ...core.utils import clean_seo_fieldsfrom ...file_upload.types import Uploadfrom ...shipping.types import WeightScalar-from ..types import Collection, Product, ProductImage, ProductVariant+from ..types import Category, Collection, Product, ProductImage, ProductVariantfrom ..utils import attributes_to_hstore, update_variants_namesclass CategoryInput(graphene.InputObjectType):description = graphene.String(description='Category description')name = graphene.String(description='Category name')- parent = graphene.ID(- description='''- ID of the parent category. If empty, category will be top level- category.''', name='parent')+slug = graphene.String(description='Category slug')seo = SeoInput(description='Search engine optimization fields.')background_image = Upload(description='Background image file.')@@ -31,6 +28,10 @@ class CategoryCreate(ModelMutation):class Arguments:input = CategoryInput(required=True, description='Fields required to create a category.')+ parent_id = graphene.ID(+ description='''+ ID of the parent category. If empty, category will be top level+ category.''', name='parent')class Meta:description = 'Creates a new category.'@@ -41,6 +42,11 @@ class CategoryCreate(ModelMutation):cleaned_input = super().clean_input(info, instance, input, errors)if 'slug' not in cleaned_input:cleaned_input['slug'] = slugify(cleaned_input['name'])+ parent_id = input['parent']+ if parent_id:+ parent = cls.get_node_or_error(+ info, parent_id, errors, field='parent', only_type=Category)+ cleaned_input['parent'] = parentclean_seo_fields(cleaned_input)return cleaned_input@@ -48,6 +54,12 @@ class CategoryCreate(ModelMutation):def user_is_allowed(cls, user, input):return user.has_perm('product.manage_products')+ @classmethod+ def mutate(cls, root, info, **data):+ parent_id = data.pop('parent_id', None)+ data['input']['parent'] = parent_id+ return super().mutate(root, info, **data)+class CategoryUpdate(CategoryCreate):class Arguments:diff --git a/tests/api/test_category.py b/tests/api/test_category.pyindex ad94a3f1e7..8d72ddf4fb 100644--- a/tests/api/test_category.py+++ b/tests/api/test_category.py@@ -54,8 +54,8 @@ def test_category_create_mutation(slug: $slugdescription: $descriptionbackgroundImage: $backgroundImage- parent: $parentId- }+ },+ parent: $parentId) {category {iddiff --git a/tests/api/test_core.py b/tests/api/test_core.pyindex 521a864446..a5b5388abc 100644--- a/tests/api/test_core.py+++ b/tests/api/test_core.py@@ -22,7 +22,7 @@ def test_user_error_field_name_for_related_object(staff_api_client, permission_manage_products):query = """mutation {- categoryCreate(input: {name: "Test", parent: "123456"}) {+ categoryCreate(input: {name: "Test"}, parent: "123456") {errors {fieldmessage