Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tighten the schema types for output fields (#9605)
Patryk Zawadzki81418cb4c078
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex 5b2bb653e0..367829459d 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -456,23 +456,23 @@ class ChoiceValue(graphene.ObjectType):class AddressValidationData(graphene.ObjectType):- country_code = graphene.String()- country_name = graphene.String()- address_format = graphene.String()- address_latin_format = graphene.String()- allowed_fields = NonNullList(graphene.String)- required_fields = NonNullList(graphene.String)- upper_fields = NonNullList(graphene.String)- country_area_type = graphene.String()- country_area_choices = NonNullList(ChoiceValue)- city_type = graphene.String()- city_choices = NonNullList(ChoiceValue)- city_area_type = graphene.String()- city_area_choices = NonNullList(ChoiceValue)- postal_code_type = graphene.String()- postal_code_matchers = NonNullList(graphene.String)- postal_code_examples = NonNullList(graphene.String)- postal_code_prefix = graphene.String()+ country_code = graphene.String(required=True)+ country_name = graphene.String(required=True)+ address_format = graphene.String(required=True)+ address_latin_format = graphene.String(required=True)+ allowed_fields = NonNullList(graphene.String, required=True)+ required_fields = NonNullList(graphene.String, required=True)+ upper_fields = NonNullList(graphene.String, required=True)+ country_area_type = graphene.String(required=True)+ country_area_choices = NonNullList(ChoiceValue, required=True)+ city_type = graphene.String(required=True)+ city_choices = NonNullList(ChoiceValue, required=True)+ city_area_type = graphene.String(required=True)+ city_area_choices = NonNullList(ChoiceValue, required=True)+ postal_code_type = graphene.String(required=True)+ postal_code_matchers = NonNullList(graphene.String, required=True)+ postal_code_examples = NonNullList(graphene.String, required=True)+ postal_code_prefix = graphene.String(required=True)class StaffNotificationRecipient(graphene.ObjectType):diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex e7123981a3..6791d3adce 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -78,9 +78,11 @@ class CheckoutLine(ModelObjectType):total_price = graphene.Field(TaxedMoney,description="The sum of the checkout line price, taxes and discounts.",+ required=True,)requires_shipping = graphene.Boolean(- description="Indicates whether the item need to be delivered."+ description="Indicates whether the item need to be delivered.",+ required=True,)class Meta:@@ -222,12 +224,14 @@ class Checkout(ModelObjectType):)email = graphene.String(description="Email of a customer.", required=False)gift_cards = NonNullList(- GiftCard, description="List of gift cards associated with this checkout."+ GiftCard,+ description="List of gift cards associated with this checkout.",+ required=True,)is_shipping_required = graphene.Boolean(description="Returns True, if checkout requires shipping.", required=True)- quantity = graphene.Int(required=True, description="The number of items purchased.")+ quantity = graphene.Int(description="The number of items purchased.", required=True)stock_reservation_expires = graphene.DateTime(description=(f"{ADDED_IN_31} Date when oldest stock reservation for this checkout "@@ -240,10 +244,12 @@ class Checkout(ModelObjectType):"A list of checkout lines, each containing information about ""an item in the checkout."),+ required=True,)shipping_price = graphene.Field(TaxedMoney,description="The price of the shipping, with all the taxes included.",+ required=True,)shipping_method = graphene.Field(ShippingMethod,@@ -262,6 +268,7 @@ class Checkout(ModelObjectType):subtotal_price = graphene.Field(TaxedMoney,description="The price of the checkout before shipping, with taxes included.",+ required=True,)token = graphene.Field(UUID, description="The checkout's token.", required=True)total_price = graphene.Field(@@ -270,9 +277,10 @@ class Checkout(ModelObjectType):"The sum of the the checkout line prices, with all the taxes,""shipping costs, and discounts included."),+ required=True,)language_code = graphene.Field(- LanguageCodeEnum, required=True, description="Checkout language code."+ LanguageCodeEnum, description="Checkout language code.", required=True)class Meta:diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex db8ebaa005..fa32425b1e 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -697,30 +697,34 @@ class Order(ModelObjectType):)available_shipping_methods = NonNullList(ShippingMethod,- required=False,description="Shipping methods that can be used with this order.",+ required=False,deprecation_reason="Use `shippingMethods`, this field will be removed in 4.0",)shipping_methods = NonNullList(- ShippingMethod, description="Shipping methods related to this order."+ ShippingMethod,+ description="Shipping methods related to this order.",+ required=True,)available_collection_points = NonNullList(Warehouse,- required=True,description=(f"{ADDED_IN_31} Collection points that can be used for this order. "f"{PREVIEW_FEATURE}"),+ required=True,)invoices = NonNullList(Invoice,- required=False,description=("List of order invoices. Requires one of the following permissions: "f"{OrderPermissions.MANAGE_ORDERS}, {AuthorizationFilters.OWNER}."),+ required=True,+ )+ number = graphene.String(+ description="User-friendly number of an order.", required=True)- number = graphene.String(description="User-friendly number of an order.")original = graphene.ID(description="The ID of the order that was the base for this order.")@@ -734,7 +738,9 @@ class Order(ModelObjectType):payment_status_display = graphene.String(description="User-friendly payment status.", required=True)- payments = NonNullList(Payment, description="List of payments for the order.")+ payments = NonNullList(+ Payment, description="List of payments for the order.", required=True+ )total = graphene.Field(TaxedMoney, description="Total amount of the order.", required=True)@@ -760,18 +766,22 @@ class Order(ModelObjectType):deprecation_reason=(f"{DEPRECATED_IN_3X_FIELD} Use `id` instead."),)voucher = graphene.Field(Voucher)- gift_cards = NonNullList(GiftCard, description="List of user gift cards.")+ gift_cards = NonNullList(+ GiftCard, description="List of user gift cards.", required=True+ )display_gross_prices = graphene.Boolean(required=True)customerNote = graphene.Boolean(required=True)customer_note = graphene.String(required=True)- weight = graphene.Field(Weight)+ weight = graphene.Field(Weight, required=True)redirect_url = graphene.String()subtotal = graphene.Field(TaxedMoney,description="The sum of line prices not including shipping.",required=True,)- status_display = graphene.String(description="User-friendly order status.")+ status_display = graphene.String(+ description="User-friendly order status.", required=True+ )can_finalize = graphene.Boolean(description=("Informs whether a draft order can be finalized"@@ -789,6 +799,7 @@ class Order(ModelObjectType):NonNullList(OrderEvent),description="List of events associated with the order.",permissions=[OrderPermissions.MANAGE_ORDERS],+ required=True,)total_balance = graphene.Field(Money,@@ -796,12 +807,12 @@ class Order(ModelObjectType):required=True,)user_email = graphene.String(- required=False,description=("Email address of the customer. Requires the following permissions to "f"access the full data: {OrderPermissions.MANAGE_ORDERS}, "f"{AuthorizationFilters.OWNER}"),+ required=False,)is_shipping_required = graphene.Boolean(description="Returns True, if order requires shipping.", required=True@@ -847,7 +858,7 @@ class Order(ModelObjectType):discounts = NonNullList("saleor.graphql.discount.types.OrderDiscount",description="List of all discounts assigned to the order.",- required=False,+ required=True,)errors = NonNullList(OrderError,@@ -1278,17 +1289,18 @@ class Order(ModelObjectType):return Promise.all([voucher, channel]).then(wrap_voucher_with_channel_context)@staticmethod- def resolve_language_code_enum(root, _info, **_kwargs):+ def resolve_language_code_enum(root: models.Order, _info, **_kwargs):return LanguageCodeEnum[str_to_enum(root.language_code)]@staticmethod- def resolve_original(root, info, **_kwargs):+ def resolve_original(root: models.Order, _info, **_kwargs):if not root.original_id:return Nonereturn graphene.Node.to_global_id("Order", root.original_id)+ @staticmethod@traced_resolver- def resolve_errors(root, info, **_kwargs):+ def resolve_errors(root: models.Order, info, **_kwargs):if root.status == OrderStatus.DRAFT:country = get_order_country(root)try:diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 164b8701df..f552bbb129 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2097,7 +2097,7 @@ type ShippingZone implements Node & ObjectWithMetadata {priceRange: MoneyRange"""List of countries available for the method."""- countries: [CountryDisplay!]+ countries: [CountryDisplay!]!"""List of shipping methods available for orders shipped to countries within this shipping zone.@@ -5953,7 +5953,7 @@ type Checkout implements Node & ObjectWithMetadata {email: String"""List of gift cards associated with this checkout."""- giftCards: [GiftCard!]+ giftCards: [GiftCard!]!"""Returns True, if checkout requires shipping."""isShippingRequired: Boolean!@@ -5969,10 +5969,10 @@ type Checkout implements Node & ObjectWithMetadata {"""A list of checkout lines, each containing information about an item in the checkout."""- lines: [CheckoutLine!]+ lines: [CheckoutLine!]!"""The price of the shipping, with all the taxes included."""- shippingPrice: TaxedMoney+ shippingPrice: TaxedMoney!"""The shipping method related with checkout."""shippingMethod: ShippingMethod @deprecated(reason: "This field will be removed in Saleor 4.0. Use `deliveryMethod` instead.")@@ -5983,7 +5983,7 @@ type Checkout implements Node & ObjectWithMetadata {deliveryMethod: DeliveryMethod"""The price of the checkout before shipping, with taxes included."""- subtotalPrice: TaxedMoney+ subtotalPrice: TaxedMoney!"""The checkout's token."""token: UUID!@@ -5991,7 +5991,7 @@ type Checkout implements Node & ObjectWithMetadata {"""The sum of the the checkout line prices, with all the taxes,shipping costs, and discounts included."""- totalPrice: TaxedMoney+ totalPrice: TaxedMoney!"""Checkout language code."""languageCode: LanguageCodeEnum!@@ -6186,10 +6186,10 @@ type CheckoutLine implements Node {quantity: Int!"""The sum of the checkout line price, taxes and discounts."""- totalPrice: TaxedMoney+ totalPrice: TaxedMoney!"""Indicates whether the item need to be delivered."""- requiresShipping: Boolean+ requiresShipping: Boolean!}"""@@ -6280,7 +6280,7 @@ type Order implements Node & ObjectWithMetadata {availableShippingMethods: [ShippingMethod!] @deprecated(reason: "Use `shippingMethods`, this field will be removed in 4.0")"""Shipping methods related to this order."""- shippingMethods: [ShippingMethod!]+ shippingMethods: [ShippingMethod!]!"""New in Saleor 3.1. Collection points that can be used for this order. Note: this feature is in a preview state and can be subject to changes at later point.@@ -6290,10 +6290,10 @@ type Order implements Node & ObjectWithMetadata {"""List of order invoices. Requires one of the following permissions: OrderPermissions.MANAGE_ORDERS, AuthorizationFilters.OWNER."""- invoices: [Invoice!]+ invoices: [Invoice!]!"""User-friendly number of an order."""- number: String+ number: String!"""The ID of the order that was the base for this order."""original: ID@@ -6311,7 +6311,7 @@ type Order implements Node & ObjectWithMetadata {paymentStatusDisplay: String!"""List of payments for the order."""- payments: [Payment!]+ payments: [Payment!]!"""Total amount of the order."""total: TaxedMoney!@@ -6329,17 +6329,17 @@ type Order implements Node & ObjectWithMetadata {voucher: Voucher"""List of user gift cards."""- giftCards: [GiftCard!]+ giftCards: [GiftCard!]!displayGrossPrices: Boolean!customerNote: String!- weight: Weight+ weight: Weight!redirectUrl: String"""The sum of line prices not including shipping."""subtotal: TaxedMoney!"""User-friendly order status."""- statusDisplay: String+ statusDisplay: String!"""Informs whether a draft order can be finalized(turned into a regular order).@@ -6355,7 +6355,7 @@ type Order implements Node & ObjectWithMetadata {"""List of events associated with the order. Requires one of the following permissions: MANAGE_ORDERS."""- events: [OrderEvent!]+ events: [OrderEvent!]!"""The difference between the paid and the order total amount."""totalBalance: Money!@@ -6387,7 +6387,7 @@ type Order implements Node & ObjectWithMetadata {translatedDiscountName: String @deprecated(reason: "This field will be removed in Saleor 4.0. Use the `discounts` field instead. ")"""List of all discounts assigned to the order."""- discounts: [OrderDiscount!]+ discounts: [OrderDiscount!]!"""List of errors that occurred during order validation."""errors: [OrderError!]!@@ -8162,23 +8162,23 @@ input AppExtensionFilterInput {}type AddressValidationData {- countryCode: String- countryName: String- addressFormat: String- addressLatinFormat: String- allowedFields: [String!]- requiredFields: [String!]- upperFields: [String!]- countryAreaType: String- countryAreaChoices: [ChoiceValue!]- cityType: String- cityChoices: [ChoiceValue!]- cityAreaType: String- cityAreaChoices: [ChoiceValue!]- postalCodeType: String- postalCodeMatchers: [String!]- postalCodeExamples: [String!]- postalCodePrefix: String+ countryCode: String!+ countryName: String!+ addressFormat: String!+ addressLatinFormat: String!+ allowedFields: [String!]!+ requiredFields: [String!]!+ upperFields: [String!]!+ countryAreaType: String!+ countryAreaChoices: [ChoiceValue!]!+ cityType: String!+ cityChoices: [ChoiceValue!]!+ cityAreaType: String!+ cityAreaChoices: [ChoiceValue!]!+ postalCodeType: String!+ postalCodeMatchers: [String!]!+ postalCodeExamples: [String!]!+ postalCodePrefix: String!}type ChoiceValue {diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.pyindex 93890ea76b..a35dae14df 100644--- a/saleor/graphql/shipping/types.py+++ b/saleor/graphql/shipping/types.py@@ -227,7 +227,9 @@ class ShippingZone(ChannelContextTypeWithMetadata, ModelObjectType):MoneyRange, description="Lowest and highest prices for the shipping.")countries = NonNullList(- CountryDisplay, description="List of countries available for the method."+ CountryDisplay,+ description="List of countries available for the method.",+ required=True,)shipping_methods = NonNullList(ShippingMethodType,