Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add prefetch to checkoutShippingMethodUpdate when retrieving checkout
NyanKiyoshi2f7b412d1609
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 45262e9dc1..e6de42c8b8 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -421,8 +421,10 @@ class CheckoutShippingMethodUpdate(BaseMutation):@classmethoddef perform_mutation(cls, _root, info, checkout_id, shipping_method_id):- checkout = cls.get_node_or_error(+ checkout_id = cls.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)shipping_method = cls.get_node_or_error(info, shipping_method_id, only_type=ShippingMethod,field='shipping_method_id')diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex 829d4b1cf9..c58021ac27 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -122,6 +122,17 @@ 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/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 5b7aab7167..dfdb964254 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -3,11 +3,10 @@ from textwrap import dedentimport graphenefrom django.conf import settingsfrom django.core.exceptions import ValidationError-from graphql_jwt.decorators import permission_requiredfrom ...core.utils import get_client_ipfrom ...core.utils.taxes import get_taxes_for_address-from ...payment import PaymentError+from ...payment import PaymentError, modelsfrom ...payment.utils import (create_payment, gateway_capture, gateway_refund, gateway_void)from ..account.i18n import I18nMixin@@ -55,8 +54,10 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):@classmethoddef perform_mutation(cls, _root, info, checkout_id, **data):- checkout = cls.get_node_or_error(- info, checkout_id, field='checkout_id', only_type=Checkout)+ checkout_id = cls.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)data = data.get('input')billing_address = checkout.billing_address