Skip to content

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

Unify countries handling

Pacu2a592fd48bd9d
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 222c79d19d..e3b9264e20 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1664,7 +1664,7 @@ type ShippingPriceUpdate {
type ShippingZone implements Node {
id: ID!
name: String!
- countries: [String]
+ countries: [CountryDisplay]
default: Boolean!
shippingMethods: [ShippingMethod]
priceRange: MoneyRange
diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.py
index 7fab569827..0811398902 100644
--- a/saleor/graphql/shipping/types.py
+++ b/saleor/graphql/shipping/types.py
@@ -8,7 +8,7 @@ from measurement.measures import Weight
from ...core.weight import convert_weight, get_default_weight_unit
from ...shipping import ShippingMethodType, models
-from ..core.types.common import CountableDjangoObjectType
+from ..core.types.common import CountableDjangoObjectType, CountryDisplay
from ..core.types.money import MoneyRange
ShippingMethodTypeEnum = graphene.Enum(
@@ -33,7 +33,7 @@ class ShippingZone(CountableDjangoObjectType):
price_range = graphene.Field(
MoneyRange, description='Lowest and highest prices for the shipping.')
countries = graphene.List(
- graphene.String,
+ CountryDisplay,
description='List of countries available for the method.')
shipping_methods = graphene.List(
ShippingMethod,
@@ -57,7 +57,9 @@ class ShippingZone(CountableDjangoObjectType):
return self.price_range
def resolve_countries(self, info):
- return self.countries
+ return [
+ CountryDisplay(code=country.code, country=country.name)
+ for country in self.countries]
def resolve_shipping_methods(self, info):
return self.shipping_methods.all()
diff --git a/tests/api/test_shipping_method.py b/tests/api/test_shipping_method.py
index dacc71b816..77300da4e5 100644
--- a/tests/api/test_shipping_method.py
+++ b/tests/api/test_shipping_method.py
@@ -134,7 +134,9 @@ CREATE_SHIPPING_ZONE_QUERY = """
}
shippingZone {
name
- countries
+ countries {
+ code
+ }
default
}
}
@@ -153,7 +155,7 @@ def test_create_shipping_zone(admin_api_client):
assert not data['errors']
zone = data['shippingZone']
assert zone['name'] == 'test shipping'
- assert zone['countries'] == ['PL']
+ assert zone['countries'] == [{'code': 'PL'}]
assert zone['default'] == False