Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Convert snake_case field names to camelCase
Adam Janik0554e2710515
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex 1b46d73dcc..a5f91cc356 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -13,6 +13,7 @@ from ..account.types import Userfrom ..file_upload.types import Uploadfrom ..utils import get_node, get_nodesfrom .types.common import Error+from .utils import snake_to_camel_caseregistry = get_global_registry()@@ -199,6 +200,7 @@ class ModelMutation(BaseMutation):if field in cls._meta.exclude:continuefor message in message_dict[field]:+ field = snake_to_camel_case(field)cls.add_error(errors, field, message)return errorsdiff --git a/saleor/graphql/core/utils.py b/saleor/graphql/core/utils.pyindex 5a1702ab5b..ceef852950 100644--- a/saleor/graphql/core/utils.py+++ b/saleor/graphql/core/utils.py@@ -4,3 +4,11 @@ def clean_seo_fields(data):if seo_fields:data['seo_title'] = seo_fields.get('title')data['seo_description'] = seo_fields.get('description')+++def snake_to_camel_case(name):+ """Convert snake_case variable name to camelCase."""+ if isinstance(name, str):+ splitted = name.split('_')+ return splitted[0] + "".join(map(str.capitalize, splitted[1:]))+ return namediff --git a/tests/api/test_core.py b/tests/api/test_core.pyindex 1ab58ee949..4e7bd768b1 100644--- a/tests/api/test_core.py+++ b/tests/api/test_core.py@@ -9,7 +9,7 @@ from django_prices_vatlayer.models import VATfrom tests.utils import get_graphql_contentfrom saleor.core.permissions import MODELS_PERMISSIONS-from saleor.graphql.core.utils import clean_seo_fields+from saleor.graphql.core.utils import clean_seo_fields, snake_to_camel_casefrom saleor.graphql.product import types as product_typesfrom saleor.graphql.utils import get_database_idfrom .utils import assert_no_permission@@ -246,3 +246,8 @@ def test_get_database_id(product):node_id = graphene.Node.to_global_id('Product', product.pk)pk = get_database_id(info, node_id, product_types.Product)assert int(pk) == product.pk+++def test_snake_to_camel_case():+ assert snake_to_camel_case('test_camel_case') == 'testCamelCase'+ assert snake_to_camel_case('testCamel_case') == 'testCamelCase'