Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change siganture of the query and set some fields as optional
Adam Janik5e8b16f3bb61
diff --git a/saleor/graphql/account/enums.py b/saleor/graphql/account/enums.pyindex 0acbc90c7f..757090f47b 100644--- a/saleor/graphql/account/enums.py+++ b/saleor/graphql/account/enums.py@@ -1,11 +1,18 @@import graphene+from django_countries import countriesfrom ...checkout import AddressTypefrom ...graphql.core.enums import to_enum+from ..core.utils import str_to_enumAddressTypeEnum = to_enum(AddressType, type_name="AddressTypeEnum")+CountryCodeEnum = graphene.Enum(+ "CountryCode", [(str_to_enum(country[0]), country[0]) for country in countries]+)++class StaffMemberStatus(graphene.Enum):ACTIVE = "active"DEACTIVATED = "deactivated"diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex 4037f5ac14..9a58f4cecd 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -40,8 +40,7 @@ def resolve_staff_users(info, query):return gql_optimizer.query(qs, info)-def resolve_address_validator(info, data):- country_code = data["country_code"]+def resolve_address_validator(info, country_code, country_area, city_area):if not country_code:client_ip = get_client_ip(info.context)country = get_country_by_ip(client_ip)@@ -51,8 +50,8 @@ def resolve_address_validator(info, data):return Noneparams = {"country_code": country_code,- "country_area": data["country_area"],- "city_area": data["city_area"],+ "country_area": country_area,+ "city_area": city_area,}rules = get_validation_rules(params)return AddressValidationData(diff --git a/saleor/graphql/account/schema.py b/saleor/graphql/account/schema.pyindex f5d0ba763b..93301ec29c 100644--- a/saleor/graphql/account/schema.py+++ b/saleor/graphql/account/schema.py@@ -5,6 +5,7 @@ from ..core.fields import FilterInputConnectionFieldfrom ..core.types import FilterInputObjectTypefrom ..descriptions import DESCRIPTIONSfrom .bulk_mutations import CustomerBulkDelete, StaffBulkDelete, UserBulkSetActive+from .enums import CountryCodeEnumfrom .filters import CustomerFilter, StaffUserFilterfrom .mutations import (AddressCreate,@@ -28,7 +29,7 @@ from .mutations import (UserAvatarUpdate,)from .resolvers import resolve_address_validator, resolve_customers, resolve_staff_users-from .types import AddressValidationData, AddressValidationInput, User+from .types import AddressValidationData, Userclass CustomerFilterInput(FilterInputObjectType):@@ -42,9 +43,11 @@ class StaffUserInput(FilterInputObjectType):class AccountQueries(graphene.ObjectType):- address_validator = graphene.Field(+ address_validation_rules = graphene.Field(AddressValidationData,- input=graphene.Argument(AddressValidationInput, required=True),+ country_code=graphene.Argument(CountryCodeEnum, required=False),+ country_area=graphene.String(required=False),+ city_area=graphene.String(required=False),)customers = FilterInputConnectionField(User,@@ -65,8 +68,15 @@ class AccountQueries(graphene.ObjectType):description="Lookup an user by ID.",)- def resolve_address_validator(self, info, input):- return resolve_address_validator(info, input)+ def resolve_address_validation_rules(+ self, info, country_code=None, country_area=None, city_area=None+ ):+ return resolve_address_validator(+ info,+ country_code=country_code,+ country_area=country_area,+ city_area=city_area,+ )@permission_required("account.manage_users")def resolve_customers(self, info, query=None, **_kwargs):diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex 379b477019..8111715fa1 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -171,12 +171,6 @@ class User(CountableDjangoObjectType):)-class AddressValidationInput(graphene.InputObjectType):- country_code = graphene.String()- country_area = graphene.String()- city_area = graphene.String()--class ChoiceValue(graphene.ObjectType):raw = graphene.String()verbose = graphene.String()diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 2445f8cac3..07a16ad615 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -82,12 +82,6 @@ type AddressValidationData {postalCodePrefix: String}-input AddressValidationInput {- countryCode: String- countryArea: String- cityArea: String-}-type AssignNavigation {errors: [Error!]menu: Menu@@ -589,6 +583,259 @@ type CollectionUpdate {collection: Collection}+enum CountryCode {+ AF+ AX+ AL+ DZ+ AS+ AD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7 +2398,7 @@ type Query {checkouts(before: String, after: String, first: Int, last: Int): CheckoutCountableConnectioncheckoutLine(id: ID): CheckoutLinecheckoutLines(before: String, after: String, first: Int, last: Int): CheckoutLineCountableConnection- addressValidator(input: AddressValidationInput!): AddressValidationData+ addressValidationRules(countryCode: CountryCode, countryArea: String, cityArea: String): AddressValidationDatacustomers(filter: CustomerFilterInput, query: String, before: String, after: String, first: Int, last: Int): UserCountableConnectionme: UserstaffUsers(filter: StaffUserInput, query: String, before: String, after: String, first: Int, last: Int): UserCountableConnectiondiff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 8f46780a3e..20ba9f4744 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -1303,8 +1303,12 @@ def test_set_default_address(def test_address_validator(user_api_client):query = """- query getValidator($input: AddressValidationInput!) {- addressValidator(input: $input) {+ query getValidator(+ $country_code: CountryCode, $country_area: String, $city_area: String) {+ addressValidationRules(+ countryCode: $country_code,+ countryArea: $country_area,+ cityArea: $city_area) {countryCodecountryNameaddressFormat@@ -1313,10 +1317,10 @@ def test_address_validator(user_api_client):}}"""- variables = {"input": {"countryCode": "PL", "countryArea": None, "cityArea": None}}+ variables = {"country_code": "PL", "country_area": None, "city_area": None}response = user_api_client.post_graphql(query, variables)content = get_graphql_content(response)- data = content["data"]["addressValidator"]+ data = content["data"]["addressValidationRules"]assert data["countryCode"] == "PL"assert data["countryName"] == "POLAND"assert data["addressFormat"] is not None@@ -1330,14 +1334,18 @@ def test_address_validator_uses_geip_when_country_code_missing(user_api_client, monkeypatch):query = """- query getValidator($input: AddressValidationInput!) {- addressValidator(input: $input) {+ query getValidator(+ $country_code: CountryCode, $country_area: String, $city_area: String) {+ addressValidationRules(+ countryCode: $country_code,+ countryArea: $country_area,+ cityArea: $city_area) {countryCode,countryName}}"""- variables = {"input": {"countryCode": None, "countryArea": None, "cityArea": None}}+ variables = {"country_code": None, "country_area": None, "city_area": None}mock_country_by_ip = Mock(return_value=Mock(code="US"))monkeypatch.setattr("saleor.graphql.account.resolvers.get_client_ip",@@ -1349,15 +1357,19 @@ def test_address_validator_uses_geip_when_country_code_missing(response = user_api_client.post_graphql(query, variables)content = get_graphql_content(response)assert mock_country_by_ip.called- data = content["data"]["addressValidator"]+ data = content["data"]["addressValidationRules"]assert data["countryCode"] == "US"assert data["countryName"] == "UNITED STATES"def test_address_validator_with_country_area(user_api_client):query = """- query getValidator($input: AddressValidationInput!) {- addressValidator(input: $input) {+ query getValidator(+ $country_code: CountryCode, $country_area: String, $city_area: String) {+ addressValidationRules(+ countryCode: $country_code,+ countryArea: $country_area,+ cityArea: $city_area) {countryCodecountryNamecountryAreaType@@ -1379,11 +1391,13 @@ def test_address_validator_with_country_area(user_api_client):}"""variables = {- "input": {"countryCode": "CN", "countryArea": "Fujian Sheng", "cityArea": None}+ "country_code": "CN",+ "country_area": "Fujian Sheng",+ "city_area": None,}response = user_api_client.post_graphql(query, variables)content = get_graphql_content(response)- data = content["data"]["addressValidator"]+ data = content["data"]["addressValidationRules"]assert data["countryCode"] == "CN"assert data["countryName"] == "CHINA"assert data["countryAreaType"] == "province"