Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move from_global_id_strict_type to the GraphQL utilities
NyanKiyoshi70e7aa528fce
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex e6de42c8b8..648dfe83b9 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -24,6 +24,7 @@ from ...shipping.models import ShippingMethod as ShippingMethodModelfrom ..account.i18n import I18nMixinfrom ..account.types import AddressInput, Userfrom ..core.mutations import BaseMutation, ModelMutation+from ..core.utils import from_global_id_strict_typefrom ..order.types import Orderfrom ..product.types import ProductVariantfrom ..shipping.types import ShippingMethod@@ -421,7 +422,7 @@ class CheckoutShippingMethodUpdate(BaseMutation):@classmethoddef perform_mutation(cls, _root, info, checkout_id, shipping_method_id):- checkout_id = cls.from_global_id_strict_type(+ checkout_id = from_global_id_strict_type(info, checkout_id, only_type=Checkout, field='checkout_id')checkout = models.Checkout.objects.prefetch_related('lines__variant__product__collections').get(pk=checkout_id)diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex c58021ac27..829d4b1cf9 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -122,17 +122,6 @@ class BaseMutation(graphene.Mutation):raise ValidationError({field: str(e)})return instances- @classmethod- def from_global_id_strict_type(- cls, info, global_id, only_type, field='id'):- """Resolve a node global id with a strict given type required."""- _type, _id = graphene.Node.from_global_id(global_id)- graphene_type = info.schema.get_type(_type).graphene_type- if graphene_type != only_type:- raise ValidationError({- field: "Couldn't resolve to a node: %s" % global_id})- return _id-@classmethoddef clean_instance(cls, instance):"""Clean the instance that was created using the input data.diff --git a/saleor/graphql/core/utils.py b/saleor/graphql/core/utils.pyindex 8bdb906aa0..11c7103e0d 100644--- a/saleor/graphql/core/utils.py+++ b/saleor/graphql/core/utils.py@@ -1,3 +1,4 @@+import graphenefrom django.core.exceptions import ValidationError@@ -26,3 +27,13 @@ def validate_image_file(file, field_name):"""Validate if the file is an image."""if not file.content_type.startswith('image/'):raise ValidationError({field_name: 'Invalid file type'})+++def from_global_id_strict_type(info, global_id, only_type, field='id'):+ """Resolve a node global id with a strict given type required."""+ _type, _id = graphene.Node.from_global_id(global_id)+ graphene_type = info.schema.get_type(_type).graphene_type+ if graphene_type != only_type:+ raise ValidationError({+ field: "Couldn't resolve to a node: %s" % global_id})+ return _iddiff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex dfdb964254..d7cc820b9c 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -14,6 +14,7 @@ from ..account.types import AddressInputfrom ..checkout.types import Checkoutfrom ..core.mutations import BaseMutationfrom ..core.scalars import Decimal+from ..core.utils import from_global_id_strict_typefrom .enums import PaymentGatewayEnumfrom .types import Payment@@ -54,7 +55,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):@classmethoddef perform_mutation(cls, _root, info, checkout_id, **data):- checkout_id = cls.from_global_id_strict_type(+ checkout_id = from_global_id_strict_type(info, checkout_id, only_type=Checkout, field='checkout_id')checkout = models.Checkout.objects.prefetch_related('lines__variant__product__collections').get(pk=checkout_id)