Skip to content

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

Refactor API resolvers to staticmethods with root typing

NyanKiyoshi1f38e660b014
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9bb82c923..b75d84df29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix wrong calculation of subtotal in cart page - #4145 by @korycins
- Fix multiple checkbox selected behavior - #4146 by @benekex2
- GraphQL now prints exceptions to stderr as well as returning them or not - #4148 by @NyanKiyoshi
+- Refactored API resolvers to staticmethods with root typing - #4155 by @NyanKiyoshi
## 2.6.0
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index d6762d9e74..727b442ef0 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -61,40 +61,43 @@ class Address(CountableDjangoObjectType):
"street_address_2",
]
- def resolve_country(self, _info):
- return CountryDisplay(code=self.country.code, country=self.country.name)
+ @staticmethod
+ def resolve_country(root: models.Address, _info):
+ return CountryDisplay(code=root.country.code, country=root.country.name)
- def resolve_is_default_shipping_address(self, _info):
+ @staticmethod
+ def resolve_is_default_shipping_address(root: models.Address, _info):
"""
This field is added through annotation when using the
`resolve_addresses` resolver. It's invalid for
`resolve_default_shipping_address` and
`resolve_default_billing_address`
"""
- if not hasattr(self, "user_default_shipping_address_pk"):
+ if not hasattr(root, "user_default_shipping_address_pk"):
return None
user_default_shipping_address_pk = getattr(
- self, "user_default_shipping_address_pk"
+ root, "user_default_shipping_address_pk"
)
- if user_default_shipping_address_pk == self.pk:
+ if user_default_shipping_address_pk == root.pk:
return True
return False
- def resolve_is_default_billing_address(self, _info):
+ @staticmethod
+ def resolve_is_default_billing_address(root: models.Address, _info):
"""
This field is added through annotation when using the
`resolve_addresses` resolver. It's invalid for
`resolve_default_shipping_address` and
`resolve_default_billing_address`
"""
- if not hasattr(self, "user_default_billing_address_pk"):
+ if not hasattr(root, "user_default_billing_address_pk"):
return None
user_default_billing_address_pk = getattr(
- self, "user_default_billing_address_pk"
+ root, "user_default_billing_address_pk"
)
- if user_default_billing_address_pk == self.pk:
+ if user_default_billing_address_pk == root.pk:
return True
return False
@@ -128,19 +131,19 @@ class CustomerEvent(CountableDjangoObjectType):
only_fields = ["id"]
@staticmethod
- def resolve_message(node, _info):
- return node.parameters.get("message", None)
+ def resolve_message(root: models.CustomerEvent, _info):
+ return root.parameters.get("message", None)
@staticmethod
- def resolve_count(node, _info):
- return node.parameters.get("count", None)
+ def resolve_count(root: models.CustomerEvent, _info):
+ return root.parameters.get("count", None)
@staticmethod
- def resolve_order_line(node, info):
- if "order_line_pk" in node.parameters:
+ def resolve_order_line(root: models.CustomerEvent, info):
+ if "order_line_pk" in root.parameters:
try:
qs = order_models.OrderLine.objects
- order_line_pk = node.parameters["order_line_pk"]
+ order_line_pk = root.parameters["order_line_pk"]
return get_node_optimized(qs, {"pk": order_line_pk}, info)
except order_models.OrderLine.DoesNotExist:
pass
@@ -192,39 +195,46 @@ class User(CountableDjangoObjectType):
"token",
]
- def resolve_addresses(self, _info, **_kwargs):
- return self.addresses.annotate_default(self).all()
+ @staticmethod
+ def resolve_addresses(root: models.User, _info, **_kwargs):
+ return root.addresses.annotate_default(root).all()
- def resolve_checkout(self, _info, **_kwargs):
- return get_user_checkout(self)
+ @staticmethod
+ def resolve_checkout(root: models.User, _info, **_kwargs):
+ return get_user_checkout(root)
- def resolve_permissions(self, _info, **_kwargs):
- if self.is_superuser:
+ @staticmethod
+ def resolve_permissions(root: models.User, _info, **_kwargs):
+ if root.is_superuser:
permissions = get_permissions()
else:
- permissions = self.user_permissions.prefetch_related(
+ permissions = root.user_permissions.prefetch_related(
"content_type"
).order_by("codename")
return format_permissions_for_display(permissions)
+ @staticmethod
@permission_required("account.manage_users")
- def resolve_note(self, _info):
- return self.note
+ def resolve_note(root: models.User, _info):
+ return root.note
+ @staticmethod
@permission_required("account.manage_users")
- def resolve_events(self, _info):
- return self.events.all()
+ def resolve_events(root: models.User, _info):
+ return root.events.all()
- def resolve_orders(self, info, **_kwargs):
+ @staticmethod
+ def resolve_orders(root: models.User, info, **_kwargs):
viewer = info.context.user
if viewer.has_perm("order.manage_orders"):
- return self.orders.all()
- return self.orders.confirmed()
+ return root.orders.all()
+ return root.orders.confirmed()
- def resolve_avatar(self, info, size=None, **_kwargs):
- if self.avatar:
+ @staticmethod
+ def resolve_avatar(root: models.User, info, size=None, **_kwargs):
+ if root.avatar:
return Image.get_adjusted(
- image=self.avatar,
+ image=root.avatar,
alt=None,
size=size,
rendition_key_set="user_avatars",
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index 7baad335dc..4fa8425126 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -14,7 +14,7 @@ from ..shipping.types import ShippingMethod
class CheckoutLine(CountableDjangoObjectType):
total_price = graphene.Field(
TaxedMoney,
- description=("The sum of the checkout line price, taxes and discounts."),
+ description="The sum of the checkout line price, taxes and discounts.",
)
requires_shipping = graphene.Boolean(
description="Indicates whether the item need to be delivered."
@@ -27,12 +27,14 @@ class CheckoutLine(CountableDjangoObjectType):
model = models.CheckoutLine
filter_fields = ["id"]
- def resolve_total_price(self, info):
- taxes = get_taxes_for_address(self.checkout.shipping_address)
- return self.get_total(discounts=info.context.discounts, taxes=taxes)
+ @staticmethod
+ def resolve_total_price(root: models.CheckoutLine, info):
+ taxes = get_taxes_for_address(root.checkout.shipping_address)
+ return root.get_total(discounts=info.context.discounts, taxes=taxes)
- def resolve_requires_shipping(self, *_args):
- return self.is_shipping_required()
+ @staticmethod
+ def resolve_requires_shipping(root: models.CheckoutLine, *_args):
+ return root.is_shipping_required()
class Checkout(CountableDjangoObjectType):
@@ -66,7 +68,7 @@ class Checkout(CountableDjangoObjectType):
)
subtotal_price = graphene.Field(
TaxedMoney,
- description=("The price of the checkout before shipping, with taxes included."),
+ description="The price of the checkout before shipping, with taxes included.",
)
total_price = graphene.Field(
TaxedMoney,
@@ -98,28 +100,35 @@ class Checkout(CountableDjangoObjectType):
interfaces = [graphene.relay.Node]
filter_fields = ["token"]
- def resolve_total_price(self, info):
- taxes = get_taxes_for_address(self.shipping_address)
- return self.get_total(discounts=info.context.discounts, taxes=taxes)
-
- def resolve_subtotal_price(self, *_args):
- taxes = get_taxes_for_address(self.shipping_address)
- return self.get_subtotal(taxes=taxes)
-
- def resolve_shipping_price(self, *_args):
- taxes = get_taxes_for_address(self.shipping_address)
- return self.get_shipping_price(taxes=taxes)
-
- def resolve_lines(self, *_args):
- return self.lines.prefetch_related("variant")
-
- def resolve_available_shipping_methods(self, info):
- taxes = get_taxes_for_address(self.shipping_address)
- price = self.get_subtotal(taxes=taxes, discounts=info.context.discounts)
- return applicable_shipping_methods(self, price.gross.amount)
-
- def resolve_available_payment_gateways(self, _info):
+ @staticmethod
+ def resolve_total_price(root: models.Checkout, info):
+ taxes = get_taxes_for_address(root.shipping_address)
+ return root.get_total(discounts=info.context.discounts, taxes=taxes)
+
+ @staticmethod
+ def resolve_subtotal_price(root: models.Checkout, *_args):
+ taxes = get_taxes_for_address(root.shipping_address)
+ return root.get_subtotal(taxes=taxes)
+
+ @staticmethod
+ def resolve_shipping_price(root: models.Checkout, *_args):
+ taxes = get_taxes_for_address(root.shipping_address)
+ return root.get_shipping_price(taxes=taxes)
+
+ @staticmethod
+ def resolve_lines(root: models.Checkout, *_args):
+ return root.lines.prefetch_related("variant")
+
+ @staticmethod
+ def resolve_available_shipping_methods(root: models.Checkout, info):
+ taxes = get_taxes_for_address(root.shipping_address)
+ price = root.get_subtotal(taxes=taxes, discounts=info.context.discounts)
+ return applicable_shipping_methods(root, price.gross.amount)
+
+ @staticmethod
+ def resolve_available_payment_gateways(_: models.Checkout, _info):
return settings.CHECKOUT_PAYMENT_GATEWAYS.keys()
- def resolve_is_shipping_required(self, _info):
- return self.is_shipping_required()
+ @staticmethod
+ def resolve_is_shipping_required(root: models.Checkout, _info):
+ return root.is_shipping_required()
diff --git a/saleor/graphql/core/types/money.py b/saleor/graphql/core/types/money.py
index 0e0c3e91af..03ba2ccc8c 100644
--- a/saleor/graphql/core/types/money.py
+++ b/saleor/graphql/core/types/money.py
@@ -14,8 +14,9 @@ class Money(graphene.ObjectType):
class Meta:
description = "Represents amount of money in specific currency."
- def resolve_localized(self, _info):
- return prices_i18n.amount(self)
+ @staticmethod
+ def resolve_localized(root, _info):
+ return prices_i18n.amount(root)
class MoneyRange(graphene.ObjectType):
@@ -62,11 +63,13 @@ class VAT(graphene.ObjectType):
class Meta:
description = "Represents a VAT rate for a country."
- def resolve_standard_rate(self, _info):
- return self.data.get("standard_rate")
+ @staticmethod
+ def resolve_standard_rate(root, _info):
+ return root.data.get("standard_rate")
- def resolve_reduced_rates(self, _info):
- reduced_rates = self.data.get("reduced_rates", {}) or {}
+ @staticmethod
+ def resolve_reduced_rates(root, _info):
+ reduced_rates = root.data.get("reduced_rates", {}) or {}
return [
ReducedRate(rate=rate, rate_type=rate_type)
for rate_type, rate in reduced_rates.items()
diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.py
index 8c11d468d1..1143f3aff9 100644
--- a/saleor/graphql/discount/types.py
+++ b/saleor/graphql/discount/types.py
@@ -38,7 +38,7 @@ class Sale(CountableDjangoObjectType):
description="A language code to return the translation for.",
required=True,
),
- description=("Returns translated sale fields for the given language code."),
+ description="Returns translated sale fields for the given language code.",
resolver=resolve_translation,
)
@@ -50,14 +50,17 @@ class Sale(CountableDjangoObjectType):
model = models.Sale
only_fields = ["end_date", "id", "name", "start_date", "type", "value"]
- def resolve_categories(self, *_args, **_kwargs):
- return self.categories.all()
+ @staticmethod
+ def resolve_categories(root: models.Sale, *_args, **_kwargs):
+ return root.categories.all()
- def resolve_collections(self, info, **_kwargs):
- return self.collections.visible_to_user(info.context.user)
+ @staticmethod
+ def resolve_collections(root: models.Sale, info, **_kwargs):
+ return root.collections.visible_to_user(info.context.user)
- def resolve_products(self, info, **_kwargs):
- return self.products.visible_to_user(info.context.user)
+ @staticmethod
+ def resolve_products(root: models.Sale, info, **_kwargs):
+ return root.products.visible_to_user(info.context.user)
class Voucher(CountableDjangoObjectType):
@@ -90,7 +93,7 @@ class Voucher(CountableDjangoObjectType):
description="A language code to return the translation for.",
required=True,
),
- description=("Returns translated Voucher fields for the given language code."),
+ description="Returns translated Voucher fields for the given language code.",
resolver=resolve_translation,
)
@@ -116,17 +119,21 @@ class Voucher(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Voucher
- def resolve_categories(self, *_args, **_kwargs):
- return self.categories.all()
+ @staticmethod
+ def resolve_categories(root: models.Voucher, *_args, **_kwargs):
+ return root.categories.all()
- def resolve_collections(self, info, **_kwargs):
- return self.collections.visible_to_user(info.context.user)
+ @staticmethod
+ def resolve_collections(root: models.Voucher, info, **_kwargs):
+ return root.collections.visible_to_user(info.context.user)
- def resolve_products(self, info, **_kwargs):
- return self.products.visible_to_user(info.context.user)
+ @staticmethod
+ def resolve_products(root: models.Voucher, info, **_kwargs):
+ return root.products.visible_to_user(info.context.user)
- def resolve_countries(self, *_args, **_kwargs):
+ @staticmethod
+ def resolve_countries(root: models.Voucher, *_args, **_kwargs):
return [
CountryDisplay(code=country.code, country=country.name)
- for country in self.countries
+ for country in root.countries
]
diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.py
index 0acb43d1c4..5a67139bbe 100644
--- a/saleor/graphql/menu/types.py
+++ b/saleor/graphql/menu/types.py
@@ -29,10 +29,11 @@ class Menu(CountableDjangoObjectType):
only_fields = ["id", "name"]
model = models.Menu
- def resolve_items(self, _info, **_kwargs):
- if hasattr(self, "prefetched_items"):
- return self.prefetched_items
- return self.items.filter(level=0)
+ @staticmethod
+ def resolve_items(root: models.Menu, _info, **_kwargs):
+ if hasattr(root, "prefetched_items"):
+ return root.prefetched_items
+ return root.items.filter(level=0)
class MenuItem(CountableDjangoObjectType):
@@ -70,14 +71,15 @@ class MenuItem(CountableDjangoObjectType):
]
model = models.MenuItem
- def resolve_children(self, _info, **_kwargs):
- return self.children.all()
+ @staticmethod
+ def resolve_children(root: models.MenuItem, _info, **_kwargs):
+ return root.children.all()
class MenuItemMoveInput(graphene.InputObjectType):
item_id = graphene.ID(description="The menu item ID to move.", required=True)
parent_id = graphene.ID(
- description=("ID of the parent menu. If empty, menu will be top level menu.")
+ description="ID of the parent menu. If empty, menu will be top level menu."
)
sort_order = graphene.Int(
description="Sorting position of the menu item (from 0 to x)."
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 7a0fee34aa..f1f1f9e4f9 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -60,40 +60,51 @@ class OrderEvent(CountableDjangoObjectType):
interfaces = [relay.Node]
only_fields = ["id"]
- def resolve_email(self, _info):
- return self.parameters.get("email", None)
+ @staticmethod
+ def resolve_email(root: models.OrderEvent, _info):
+ return root.parameters.get("email", None)
- def resolve_email_type(self, _info):
- return self.parameters.get("email_type", None)
+ @staticmethod
+ def resolve_email_type(root: models.OrderEvent, _info):
+ return root.parameters.get("email_type", None)
- def resolve_amount(self, _info):
- amount = self.parameters.get("amount", None)
+ @staticmethod
+ def resolve_amount(root: models.OrderEvent, _info):
+ amount = root.parameters.get("amount", None)
return float(amount) if amount else None
- def resolve_payment_id(self, _info):
- return self.parameters.get("payment_id", None)
+ @staticmethod
+ def resolve_payment_id(root: models.OrderEvent, _info):
+ return root.parameters.get("payment_id", None)
- def resolve_payment_gateway(self, _info):
- return self.parameters.get("payment_gateway", None)
+ @staticmethod
+ def resolve_payment_gateway(root: models.OrderEvent, _info):
+ return root.parameters.get("payment_gateway", None)
- def resolve_quantity(self, _info):
- quantity = self.parameters.get("quantity", None)
+ @staticmethod
+ def resolve_quantity(root: models.OrderEvent, _info):
+ quantity = root.parameters.get("quantity", None)
return int(quantity) if quantity else None
- def resolve_message(self, _info):
- return self.parameters.get("message", None)
+ @staticmethod
+ def resolve_message(root: models.OrderEvent, _info):
+ return root.parameters.get("message", None)
- def resolve_composed_id(self, _info):
- return self.parameters.get("composed_id", None)
+ @staticmethod
+ def resolve_composed_id(root: models.OrderEvent, _info):
+ return root.parameters.get("composed_id", None)
- def resolve_oversold_items(self, _info):
- return self.parameters.get("oversold_items", None)
+ @staticmethod
+ def resolve_oversold_items(root: models.OrderEvent, _info):
+ return root.parameters.get("oversold_items", None)
- def resolve_order_number(self, _info):
- return self.order_id
+ @staticmethod
+ def resolve_order_number(root: models.OrderEvent, _info):
+ return root.order_id
- def resolve_lines(self, _info):
- raw_lines = self.parameters.get("lines", None)
+ @staticmethod
+ def resolve_lines(root: models.OrderEvent, _info):
+ raw_lines = root.parameters.get("lines", None)
if not raw_lines:
return None
@@ -120,8 +131,9 @@ class OrderEvent(CountableDjangoObjectType):
return results
- def resolve_fulfilled_items(self, _info):
- lines = self.parameters.get("fulfilled_items", None)
+ @staticmethod
+ def resolve_fulfilled_items(root: models.OrderEvent, _info):
+ lines = root.parameters.get("fulfilled_items", None)
return models.FulfillmentLine.objects.filter(pk__in=lines)
@@ -134,9 +146,10 @@ class FulfillmentLine(CountableDjangoObjectType):
model = models.FulfillmentLine
only_fields = ["id", "quantity"]
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="order_line")
- def resolve_order_line(self, _info):
- return self.order_line
+ def resolve_order_line(root: models.FulfillmentLine, _info):
+ return root.order_line
class Fulfillment(CountableDjangoObjectType):
@@ -158,18 +171,20 @@ class Fulfillment(CountableDjangoObjectType):
"tracking_number",
]
- def resolve_lines(self, _info):
- return self.lines.all()
+ @staticmethod
+ def resolve_lines(root: models.Fulfillment, _info):
+ return root.lines.all()
- def resolve_status_display(self, _info):
- return self.get_status_display()
+ @staticmethod
+ def resolve_status_display(root: models.Fulfillment, _info):
+ return root.get_status_display()
class OrderLine(CountableDjangoObjectType):
thumbnail_url = graphene.String(
description="The URL of a main thumbnail for the ordered product.",
size=graphene.Int(description="Size of the image"),
- deprecation_reason=("thumbnailUrl is deprecated, use thumbnail instead"),
+ deprecation_reason="thumbnailUrl is deprecated, use thumbnail instead",
)
thumbnail = graphene.Field(
Image,
@@ -203,34 +218,37 @@ class OrderLine(CountableDjangoObjectType):
"translated_product_name",
]
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=["variant__images", "variant__product__images"]
)
- def resolve_thumbnail_url(self, info, size=None):
- if not self.variant_id:
+ def resolve_thumbnail_url(root: models.OrderLine, info, size=None):
+ if not root.variant_id:
return None
if not size:
size = 255
url = get_product_image_thumbnail(
- self.variant.get_first_image(), size, method="thumbnail"
+ root.variant.get_first_image(), size, method="thumbnail"
)
return info.context.build_absolute_uri(url)
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=["variant__images", "variant__product__images"]
)
- def resolve_thumbnail(self, info, *, size=None):
- if not self.variant_id:
+ def resolve_thumbnail(root: models.OrderLine, info, *, size=None):
+ if not root.variant_id:
return None
if not size:
size = 255
- image = self.variant.get_first_image()
+ image = root.variant.get_first_image()
url = get_product_image_thumbnail(image, size, method="thumbnail")
alt = image.alt if image else None
return Image(alt=alt, url=info.context.build_absolute_uri(url))
- def resolve_unit_price(self, _info):
- return self.unit_price
+ @staticmethod
+ def resolve_unit_price(root: models.OrderLine, _info):
+ return root.unit_price
class Order(CountableDjangoObjectType):
@@ -329,94 +347,114 @@ class Order(CountableDjangoObjectType):
"weight",
]
- def resolve_shipping_price(self, _info):
- return self.shipping_price
+ @staticmethod
+ def resolve_shipping_price(root: models.Order, _info):
+ return root.shipping_price
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments__transactions")
- def resolve_actions(self, _info):
+ def resolve_actions(root: models.Order, _info):
actions = []
- payment = self.get_last_payment()
- if self.can_capture(payment):
+ payment = root.get_last_payment()
+ if root.can_capture(payment):
actions.append(OrderAction.CAPTURE)
- if self.can_mark_as_paid():
+ if root.can_mark_as_paid():
actions.append(OrderAction.MARK_AS_PAID)
- if self.can_refund(payment):
+ if root.can_refund(payment):
actions.append(OrderAction.REFUND)
- if self.can_void(payment):
+ if root.can_void(payment):
actions.append(OrderAction.VOID)
return actions
- def resolve_subtotal(self, _info):
- return self.get_subtotal()
+ @staticmethod
+ def resolve_subtotal(root: models.Order, _info):
+ return root.get_subtotal()
- def resolve_total(self, _info):
- return self.total
+ @staticmethod
+ def resolve_total(root: models.Order, _info):
+ return root.total
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments__transactions")
- def resolve_total_authorized(self, _info):
+ def resolve_total_authorized(root: models.Order, _info):
# FIXME adjust to multiple payments in the future
- return self.total_authorized
+ return root.total_authorized
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments")
- def resolve_total_captured(self, _info):
+ def resolve_total_captured(root: models.Order, _info):
# FIXME adjust to multiple payments in the future
- return self.total_captured
+ return root.total_captured
- def resolve_total_balance(self, _info):
- return self.total_balance
+ @staticmethod
+ def resolve_total_balance(root: models.Order, _info):
+ return root.total_balance
- def resolve_fulfillments(self, info):
+ @staticmethod
+ def resolve_fulfillments(root: models.Order, info):
user = info.context.user
if user.is_staff:
- qs = self.fulfillments.all()
+ qs = root.fulfillments.all()
else:
- qs = self.fulfillments.exclude(status=FulfillmentStatus.CANCELED)
+ qs = root.fulfillments.exclude(status=FulfillmentStatus.CANCELED)
return qs.order_by("pk")
- def resolve_lines(self, _info):
- return self.lines.all().order_by("pk")
+ @staticmethod
+ def resolve_lines(root: models.Order, _info):
+ return root.lines.all().order_by("pk")
- def resolve_events(self, _info):
- return self.events.all().order_by("pk")
+ @staticmethod
+ def resolve_events(root: models.Order, _info):
+ return root.events.all().order_by("pk")
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments")
- def resolve_is_paid(self, _info):
- return self.is_fully_paid()
+ def resolve_is_paid(root: models.Order, _info):
+ return root.is_fully_paid()
- def resolve_number(self, _info):
- return str(self.pk)
+ @staticmethod
+ def resolve_number(root: models.Order, _info):
+ return str(root.pk)
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments")
- def resolve_payment_status(self, _info):
- return self.get_payment_status()
+ def resolve_payment_status(root: models.Order, _info):
+ return root.get_payment_status()
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="payments")
- def resolve_payment_status_display(self, _info):
- return self.get_payment_status_display()
+ def resolve_payment_status_display(root: models.Order, _info):
+ return root.get_payment_status_display()
- def resolve_payments(self, _info):
- return self.payments.all()
+ @staticmethod
+ def resolve_payments(root: models.Order, _info):
+ return root.payments.all()
- def resolve_status_display(self, _info):
- return self.get_status_display()
+ @staticmethod
+ def resolve_status_display(root: models.Order, _info):
+ return root.get_status_display()
- def resolve_can_finalize(self, _info):
+ @staticmethod
+ def resolve_can_finalize(root: models.Order, _info):
try:
- validate_draft_order(self)
+ validate_draft_order(root)
except ValidationError:
return False
return True
+ @staticmethod
@gql_optimizer.resolver_hints(select_related="user")
- def resolve_user_email(self, _info):
- if self.user_email:
- return self.user_email
- if self.user_id:
- return self.user.email
+ def resolve_user_email(root: models.Order, _info):
+ if root.user_email:
+ return root.user_email
+ if root.user_id:
+ return root.user.email
return None
- def resolve_available_shipping_methods(self, _info):
- return applicable_shipping_methods(self, self.get_subtotal().gross.amount)
+ @staticmethod
+ def resolve_available_shipping_methods(root: models.Order, _info):
+ return applicable_shipping_methods(root, root.get_subtotal().gross.amount)
- def resolve_is_shipping_required(self, _info):
- return self.is_shipping_required()
+ @staticmethod
+ def resolve_is_shipping_required(root: models.Order, _info):
+ return root.is_shipping_required()
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index e3e08d2221..b402a8c6e8 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -44,8 +44,10 @@ class Page(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Page
- def resolve_available_on(self, _info):
- return self.publication_date
+ @staticmethod
+ def resolve_available_on(root: models.Page, _info):
+ return root.publication_date
- def resolve_is_visible(self, _info):
- return self.is_published
+ @staticmethod
+ def resolve_is_visible(root: models.Page, _info):
+ return root.is_published
diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.py
index 92bf90dd79..28ceaf10c8 100644
--- a/saleor/graphql/payment/types.py
+++ b/saleor/graphql/payment/types.py
@@ -29,8 +29,9 @@ class Transaction(CountableDjangoObjectType):
"gateway_response",
]
- def resolve_amount(self, _info):
- return self.get_amount()
+ @staticmethod
+ def resolve_amount(root: models.Transaction, _info):
+ return root.get_amount()
class CreditCard(graphene.ObjectType):
@@ -98,61 +99,69 @@ class Payment(CountableDjangoObjectType):
"extra_data",
]
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="transactions")
- def resolve_actions(self, _info):
+ def resolve_actions(root: models.Payment, _info):
actions = []
- if self.can_capture():
+ if root.can_capture():
actions.append(OrderAction.CAPTURE)
- if self.can_refund():
+ if root.can_refund():
actions.append(OrderAction.REFUND)
- if self.can_void():
+ if root.can_void():
actions.append(OrderAction.VOID)
return actions
- def resolve_total(self, _info):
- return self.get_total()
+ @staticmethod
+ def resolve_total(root: models.Payment, _info):
+ return root.get_total()
- def resolve_captured_amount(self, _info):
- return self.get_captured_amount()
+ @staticmethod
+ def resolve_captured_amount(root: models.Payment, _info):
+ return root.get_captured_amount()
- def resolve_billing_address(self, _info):
+ @staticmethod
+ def resolve_billing_address(root: models.Payment, _info):
return Address(
- first_name=self.billing_first_name,
- last_name=self.billing_last_name,
- company_name=self.billing_company_name,
- street_address_1=self.billing_address_1,
- street_address_2=self.billing_address_2,
- city=self.billing_city,
- city_area=self.billing_city_area,
- postal_code=self.billing_postal_code,
- country=Country(self.billing_country_code),
- country_area=self.billing_country_area,
+ first_name=root.billing_first_name,
+ last_name=root.billing_last_name,
+ company_name=root.billing_company_name,
+ street_address_1=root.billing_address_1,
+ street_address_2=root.billing_address_2,
+ city=root.billing_city,
+ city_area=root.billing_city_area,
+ postal_code=root.billing_postal_code,
+ country=Country(root.billing_country_code),
+ country_area=root.billing_country_area,
)
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="transactions")
- def resolve_transactions(self, _info):
- return self.transactions.all()
+ def resolve_transactions(root: models.Payment, _info):
+ return root.transactions.all()
- def resolve_available_refund_amount(self, _info):
+ @staticmethod
+ def resolve_available_refund_amount(root: models.Payment, _info):
# FIXME TESTME
- if not self.can_refund():
+ if not root.can_refund():
return None
- return self.get_captured_amount()
+ return root.get_captured_amount()
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="transactions")
- def resolve_available_capture_amount(self, _info):
+ def resolve_available_capture_amount(root: models.Payment, _info):
# FIXME TESTME
- if not self.can_capture():
+ if not root.can_capture():
return None
- return self.get_charge_amount()
+ return root.get_charge_amount()
- def resolve_credit_card(self, _info):
+ @staticmethod
+ def resolve_credit_card(root: models.Payment, _info):
data = {
- "first_digits": self.cc_first_digits,
- "last_digits": self.cc_last_digits,
- "brand": self.cc_brand,
- "exp_month": self.cc_exp_month,
- "exp_year": self.cc_exp_year,
+ "first_digits": root.cc_first_digits,
+ "last_digits": root.cc_last_digits,
+ "brand": root.cc_brand,
+ "exp_month": root.cc_exp_month,
+ "exp_year": root.cc_exp_year,
}
if not any(data.values()):
return None
diff --git a/saleor/graphql/product/types/attributes.py b/saleor/graphql/product/types/attributes.py
index 5cb8095fa3..0c223ab682 100644
--- a/saleor/graphql/product/types/attributes.py
+++ b/saleor/graphql/product/types/attributes.py
@@ -50,8 +50,9 @@ class AttributeValue(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.AttributeValue
- def resolve_type(self, *_args):
- return resolve_attribute_value_type(self.value)
+ @staticmethod
+ def resolve_type(root: models.AttributeValue, *_args):
+ return resolve_attribute_value_type(root.value)
class Attribute(CountableDjangoObjectType):
@@ -82,8 +83,9 @@ class Attribute(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Attribute
- def resolve_values(self, *_args):
- return self.values.all()
+ @staticmethod
+ def resolve_values(root: models.Attribute, *_args):
+ return root.values.all()
class SelectedAttribute(graphene.ObjectType):
diff --git a/saleor/graphql/product/types/digital_contents.py b/saleor/graphql/product/types/digital_contents.py
index 42a3f2626a..525fe4380b 100644
--- a/saleor/graphql/product/types/digital_contents.py
+++ b/saleor/graphql/product/types/digital_contents.py
@@ -14,8 +14,9 @@ class DigitalContentUrl(CountableDjangoObjectType):
only_fields = ["content", "created", "download_num", "token", "url"]
interfaces = (relay.Node,)
- def resolve_url(self, *_args):
- return self.get_absolute_url()
+ @staticmethod
+ def resolve_url(root: models.DigitalContentUrl, *_args):
+ return root.get_absolute_url()
class DigitalContent(CountableDjangoObjectType):
@@ -40,6 +41,7 @@ class DigitalContent(CountableDjangoObjectType):
]
interfaces = (relay.Node,)
- def resolve_urls(self, info, **_kwargs):
- qs = self.urls.all()
+ @staticmethod
+ def resolve_urls(root: models.DigitalContent, info, **_kwargs):
+ qs = root.urls.all()
return gql_optimizer.query(qs, info)
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 550881e6a8..f0447c1f36 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -236,71 +236,84 @@ class ProductVariant(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.ProductVariant
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_digital_content(self, *_args):
- return getattr(self, "digital_content", None)
+ def resolve_digital_content(root: models.ProductVariant, *_args):
+ return getattr(root, "digital_content", None)
- def resolve_stock_quantity(self, *_args):
- return self.quantity_available
+ @staticmethod
+ def resolve_stock_quantity(root: models.ProductVariant, *_args):
+ return root.quantity_available
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related="product__product_type__variant_attributes__values"
)
- def resolve_attributes(self, *_args):
- attributes_qs = self.product.product_type.variant_attributes.all()
- return resolve_attribute_list(self.attributes, attributes_qs)
+ def resolve_attributes(root: models.ProductVariant, *_args):
+ attributes_qs = root.product.product_type.variant_attributes.all()
+ return resolve_attribute_list(root.attributes, attributes_qs)
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_margin(self, *_args):
- return get_margin_for_variant(self)
+ def resolve_margin(root: models.ProductVariant, *_args):
+ return get_margin_for_variant(root)
- def resolve_price(self, *_args):
+ @staticmethod
+ def resolve_price(root: models.ProductVariant, *_args):
return (
- self.price_override
- if self.price_override is not None
- else self.product.price
+ root.price_override
+ if root.price_override is not None
+ else root.product.price
)
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=("product",), only=["price_override"]
)
- def resolve_pricing(self, info):
+ def resolve_pricing(root: models.ProductVariant, info):
context = info.context
availability = get_variant_availability(
- self, context.discounts, context.taxes, context.currency
+ root, context.discounts, context.taxes, context.currency
)
return VariantPricingInfo(**availability._asdict())
resolve_availability = resolve_pricing
- def resolve_is_available(self, _info):
- return self.is_available
+ @staticmethod
+ def resolve_is_available(root: models.ProductVariant, _info):
+ return root.is_available
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_price_override(self, *_args):
- return self.price_override
+ def resolve_price_override(root: models.ProductVariant, *_args):
+ return root.price_override
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_quantity(self, *_args):
- return self.quantity
+ def resolve_quantity(root: models.ProductVariant, *_args):
+ return root.quantity
+ @staticmethod
@permission_required(["order.manage_orders", "product.manage_products"])
- def resolve_quantity_ordered(self, *_args):
+ def resolve_quantity_ordered(root: models.ProductVariant, *_args):
# This field is added through annotation when using the
# `resolve_report_product_sales` resolver.
- return getattr(self, "quantity_ordered", None)
+ return getattr(root, "quantity_ordered", None)
+ @staticmethod
@permission_required(["order.manage_orders", "product.manage_products"])
- def resolve_quantity_allocated(self, *_args):
- return self.quantity_allocated
+ def resolve_quantity_allocated(root: models.ProductVariant, *_args):
+ return root.quantity_allocated
+ @staticmethod
@permission_required(["order.manage_orders", "product.manage_products"])
- def resolve_revenue(self, *_args, period):
+ def resolve_revenue(root: models.ProductVariant, *_args, period):
start_date = reporting_period_to_date(period)
- return calculate_revenue_for_variant(self, start_date)
+ return calculate_revenue_for_variant(root, start_date)
- def resolve_images(self, *_args):
- return self.images.all()
+ @staticmethod
+ def resolve_images(root: models.ProductVariant, *_args):
+ return root.images.all()
@classmethod
def get_node(cls, info, id):
@@ -413,18 +426,20 @@ class Product(CountableDjangoObjectType):
"weight",
]
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="images")
- def resolve_thumbnail_url(self, info, *, size=None):
+ def resolve_thumbnail_url(root: models.Product, info, *, size=None):
if not size:
size = 255
url = get_product_image_thumbnail(
- self.get_first_image(), size, method="thumbnail"
+ root.get_first_image(), size, method="thumbnail"
)
return info.context.build_absolute_uri(url)
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="images")
- def resolve_thumbnail(self, info, *, size=None):
- image = self.get_first_image()
+ def resolve_thumbnail(root: models.Product, info, *, size=None):
+ image = root.get_first_image()
if not size:
size = 255
url = get_product_image_thumbnail(image, size, method="thumbnail")
@@ -432,73 +447,86 @@ class Product(CountableDjangoObjectType):
alt = image.alt if image else None
return Image(alt=alt, url=url)
- def resolve_url(self, *_args):
- return self.get_absolute_url()
+ @staticmethod
+ def resolve_url(root: models.Product, *_args):
+ return root.get_absolute_url()
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=("variants", "collections"),
only=["publication_date", "charge_taxes", "price", "tax_rate"],
)
- def resolve_pricing(self, info):
+ def resolve_pricing(root: models.Product, info):
context = info.context
availability = get_product_availability(
- self, context.discounts, context.taxes, context.currency
+ root, context.discounts, context.taxes, context.currency
)
return ProductPricingInfo(**availability._asdict())
resolve_availability = resolve_pricing
- def resolve_is_available(self, _info):
- return self.is_available
+ @staticmethod
+ def resolve_is_available(root: models.Product, _info):
+ return root.is_available
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_base_price(self, _info):
- return self.price
+ def resolve_base_price(root: models.Product, _info):
+ return root.price
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=("variants", "collections"),
only=["publication_date", "charge_taxes", "price", "tax_rate"],
)
- def resolve_price(self, info):
- price_range = self.get_price_range(info.context.discounts)
+ def resolve_price(root: models.Product, info):
+ price_range = root.get_price_range(info.context.discounts)
return price_range.start.net
+ @staticmethod
@gql_optimizer.resolver_hints(
prefetch_related="product_type__product_attributes__values"
)
- def resolve_attributes(self, *_args):
- attributes_qs = self.product_type.product_attributes.all()
- return resolve_attribute_list(self.attributes, attributes_qs)
+ def resolve_attributes(root: models.Product, *_args):
+ attributes_qs = root.product_type.product_attributes.all()
+ return resolve_attribute_list(root.attributes, attributes_qs)
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_purchase_cost(self, *_args):
- purchase_cost, _ = get_product_costs_data(self)
+ def resolve_purchase_cost(root: models.Product, *_args):
+ purchase_cost, _ = get_product_costs_data(root)
return purchase_cost
+ @staticmethod
@permission_required("product.manage_products")
- def resolve_margin(self, *_args):
- _, margin = get_product_costs_data(self)
+ def resolve_margin(root: models.Product, *_args):
+ _, margin = get_product_costs_data(root)
return Margin(margin[0], margin[1])
- def resolve_image_by_id(self, info, id):
+ @staticmethod
+ def resolve_image_by_id(root: models.Product, info, id):
pk = get_database_id(info, id, ProductImage)
try:
- return self.images.get(pk=pk)
+ return root.images.get(pk=pk)
except models.ProductImage.DoesNotExist:
raise GraphQLError("Product image not found.")
+ @staticmethod
@gql_optimizer.resolver_hints(model_field="images")
- def resolve_images(self, *_args, **_kwargs):
- return self.images.all()
+ def resolve_images(root: models.Product, *_args, **_kwargs):
+ return root.images.all()
- def resolve_variants(self, *_args, **_kwargs):
- return self.variants.all()
+ @staticmethod
+ def resolve_variants(root: models.Product, *_args, **_kwargs):
+ return root.variants.all()
- def resolve_collections(self, *_args):
- return self.collections.all()
+ @staticmethod
+ def resolve_collections(root: models.Product, *_args):
+ return root.collections.all()
- def resolve_available_on(self, *_args):
- return self.publication_date
+ @staticmethod
+ def resolve_available_on(root: models.Product, *_args):
+ return root.publication_date
@classmethod
def get_node(cls, info, pk):
@@ -537,18 +565,21 @@ class ProductType(CountableDjangoObjectType):
"weight",
]
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="product_attributes")
- def resolve_product_attributes(self, *_args, **_kwargs):
- return self.product_attributes.all()
+ def resolve_product_attributes(root: models.ProductType, *_args, **_kwargs):
+ return root.product_attributes.all()
+ @staticmethod
@gql_optimizer.resolver_hints(prefetch_related="variant_attributes")
- def resolve_variant_attributes(self, *_args, **_kwargs):
- return self.variant_attributes.all()
-
- def resolve_products(self, info, **_kwargs):
- if hasattr(self, "prefetched_products"):
- return self.prefetched_products
- qs = self.products.visible_to_user(info.context.user)
+ def resolve_variant_attributes(root: models.ProductType, *_args, **_kwargs):
+ return root.variant_attributes.all()
+
+ @staticmethod
+ def resolve_products(root: models.ProductType, info, **_kwargs):
+ if hasattr(root, "prefetched_products"):
+ return root.prefetched_products
+ qs = root.products.visible_to_user(info.context.user)
return gql_optimizer.query(qs, info)
@@ -594,24 +625,27 @@ class Collection(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Collection
- def resolve_background_image(self, info, size=None, **_kwargs):
- if self.background_image:
+ @staticmethod
+ def resolve_background_image(root: models.Collection, info, size=None, **_kwargs):
+ if root.background_image:
return Image.get_adjusted(
- image=self.background_image,
- alt=self.background_image_alt,
+ image=root.background_image,
+ alt=root.background_image_alt,
size=size,
rendition_key_set="background_images",
info=info,
)
- def resolve_products(self, info, **_kwargs):
- if hasattr(self, "prefetched_products"):
- return self.prefetched_products
- qs = self.products.visible_to_user(info.context.user)
+ @staticmethod
+ def resolve_products(root: models.Collection, info, **_kwargs):
+ if hasattr(root, "prefetched_products"):
+ return root.prefetched_products
+ qs = root.products.visible_to_user(info.context.user)
return gql_optimizer.query(qs, info)
- def resolve_published_date(self, *_args):
- return self.publication_date
+ @staticmethod
+ def resolve_published_date(root: models.Collection, *_args):
+ return root.publication_date
@classmethod
def get_node(cls, info, id):
@@ -668,36 +702,41 @@ class Category(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Category
- def resolve_ancestors(self, info, **_kwargs):
- qs = self.get_ancestors()
+ @staticmethod
+ def resolve_ancestors(root: models.Category, info, **_kwargs):
+ qs = root.get_ancestors()
return gql_optimizer.query(qs, info)
- def resolve_background_image(self, info, size=None, **_kwargs):
- if self.background_image:
+ @staticmethod
+ def resolve_background_image(root: models.Category, info, size=None, **_kwargs):
+ if root.background_image:
return Image.get_adjusted(
- image=self.background_image,
- alt=self.background_image_alt,
+ image=root.background_image,
+ alt=root.background_image_alt,
size=size,
rendition_key_set="background_images",
info=info,
)
- def resolve_children(self, info, **_kwargs):
- qs = self.children.all()
+ @staticmethod
+ def resolve_children(root: models.Category, info, **_kwargs):
+ qs = root.children.all()
return gql_optimizer.query(qs, info)
- def resolve_url(self, _info):
- return self.get_absolute_url()
+ @staticmethod
+ def resolve_url(root: models.Category, _info):
+ return root.get_absolute_url()
- def resolve_products(self, info, **_kwargs):
+ @staticmethod
+ def resolve_products(root: models.Category, info, **_kwargs):
# If the category has no children, we use the prefetched data.
- children = self.children.all()
- if not children and hasattr(self, "prefetched_products"):
- return self.prefetched_products
+ children = root.children.all()
+ if not children and hasattr(root, "prefetched_products"):
+ return root.prefetched_products
# Otherwise we want to include products from child categories which
# requires performing additional logic.
- tree = self.get_descendants(include_self=True)
+ tree = root.get_descendants(include_self=True)
qs = models.Product.objects.published()
qs = qs.filter(category__in=tree)
return gql_optimizer.query(qs, info)
@@ -716,9 +755,10 @@ class ProductImage(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.ProductImage
- def resolve_url(self, info, *, size=None):
+ @staticmethod
+ def resolve_url(root: models.ProductImage, info, *, size=None):
if size:
- url = get_thumbnail(self.image, size, method="thumbnail")
+ url = get_thumbnail(root.image, size, method="thumbnail")
else:
- url = self.image.url
+ url = root.image.url
return info.context.build_absolute_uri(url)
diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.py
index 009add9dd2..c35adfd5e2 100644
--- a/saleor/graphql/shipping/types.py
+++ b/saleor/graphql/shipping/types.py
@@ -71,14 +71,17 @@ class ShippingZone(CountableDjangoObjectType):
interfaces = [relay.Node]
only_fields = ["default", "id", "name"]
- def resolve_price_range(self, *_args):
- return self.price_range
+ @staticmethod
+ def resolve_price_range(root: models.ShippingZone, *_args):
+ return root.price_range
- def resolve_countries(self, *_args):
+ @staticmethod
+ def resolve_countries(root: models.ShippingZone, *_args):
return [
CountryDisplay(code=country.code, country=country.name)
- for country in self.countries
+ for country in root.countries
]
- def resolve_shipping_methods(self, *_args):
- return self.shipping_methods.all()
+ @staticmethod
+ def resolve_shipping_methods(root: models.ShippingZone, *_args):
+ return root.shipping_methods.all()
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
index 90526c8955..ba1fc6dbb5 100644
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -140,11 +140,13 @@ class Shop(graphene.ObjectType):
Represents a shop resource containing general shop\'s data
and configuration."""
+ @staticmethod
@permission_required("site.manage_settings")
- def resolve_authorization_keys(self, _info):
+ def resolve_authorization_keys(_, _info):
return site_models.AuthorizationKey.objects.all()
- def resolve_countries(self, _info):
+ @staticmethod
+ def resolve_countries(_, _info):
taxes = {vat.country_code: vat for vat in VAT.objects.all()}
return [
CountryDisplay(
@@ -153,10 +155,12 @@ class Shop(graphene.ObjectType):
for country in countries
]
- def resolve_currencies(self, _info):
+ @staticmethod
+ def resolve_currencies(_, _info):
return settings.AVAILABLE_CURRENCIES
- def resolve_domain(self, info):
+ @staticmethod
+ def resolve_domain(_, info):
site = info.context.site
return Domain(
host=site.domain,
@@ -164,7 +168,8 @@ class Shop(graphene.ObjectType):
url=info.context.build_absolute_uri("/"),
)
- def resolve_geolocalization(self, info):
+ @staticmethod
+ def resolve_geolocalization(_, info):
client_ip = get_client_ip(info.context)
country = get_country_by_ip(client_ip)
if country:
@@ -173,18 +178,22 @@ class Shop(graphene.ObjectType):
)
return Geolocalization(country=None)
- def resolve_default_currency(self, _info):
+ @staticmethod
+ def resolve_default_currency(_, _info):
return settings.DEFAULT_CURRENCY
- def resolve_description(self, info):
+ @staticmethod
+ def resolve_description(_, info):
return info.context.site.settings.description
- def resolve_homepage_collection(self, info):
+ @staticmethod
+ def resolve_homepage_collection(_, info):
collection_pk = info.context.site.settings.homepage_collection_id
qs = product_models.Collection.objects.all()
return get_node_optimized(qs, {"pk": collection_pk}, info)
- def resolve_languages(self, _info):
+ @staticmethod
+ def resolve_languages(_, _info):
return [
LanguageDisplay(
code=LanguageCodeEnum[str_to_enum(language[0])], language=language[1]
@@ -192,43 +201,54 @@ class Shop(graphene.ObjectType):
for language in settings.LANGUAGES
]
- def resolve_name(self, info):
+ @staticmethod
+ def resolve_name(_, info):
return info.context.site.name
- def resolve_navigation(self, info):
+ @staticmethod
+ def resolve_navigation(_, info):
site_settings = info.context.site.settings
qs = menu_models.Menu.objects.all()
top_menu = get_node_optimized(qs, {"pk": site_settings.top_menu_id}, info)
bottom_menu = get_node_optimized(qs, {"pk": site_settings.bottom_menu_id}, info)
return Navigation(main=top_menu, secondary=bottom_menu)
+ @staticmethod
@permission_required("account.manage_users")
- def resolve_permissions(self, _info):
+ def resolve_permissions(_, _info):
permissions = get_permissions()
return format_permissions_for_display(permissions)
- def resolve_phone_prefixes(self, _info):
+ @staticmethod
+ def resolve_phone_prefixes(_, _info):
return list(COUNTRY_CODE_TO_REGION_CODE.keys())
- def resolve_header_text(self, info):
+ @staticmethod
+ def resolve_header_text(_, info):
return info.context.site.settings.header_text
- def resolve_include_taxes_in_prices(self, info):
+ @staticmethod
+ def resolve_include_taxes_in_prices(_, info):
return info.context.site.settings.include_taxes_in_prices
- def resolve_display_gross_prices(self, info):
+ @staticmethod
+ def resolve_display_gross_prices(_, info):
return info.context.site.settings.display_gross_prices
- def resolve_charge_taxes_on_shipping(self, info):
+ @staticmethod
+ def resolve_charge_taxes_on_shipping(_, info):
return info.context.site.settings.charge_taxes_on_shipping
- def resolve_track_inventory_by_default(self, info):
+ @staticmethod
+ def resolve_track_inventory_by_default(_, info):
return info.context.site.settings.track_inventory_by_default
- def resolve_default_weight_unit(self, info):
+ @staticmethod
+ def resolve_default_weight_unit(_, info):
return info.context.site.settings.default_weight_unit
- def resolve_default_country(self, _info):
+ @staticmethod
+ def resolve_default_country(_, _info):
default_country_code = settings.DEFAULT_COUNTRY
default_country_name = countries.countries.get(default_country_code)
if default_country_name:
@@ -240,20 +260,24 @@ class Shop(graphene.ObjectType):
default_country = None
return default_country
- def resolve_translation(self, info, language_code):
+ @staticmethod
+ def resolve_translation(_, info, language_code):
return resolve_translation(info.context.site.settings, info, language_code)
+ @staticmethod
@permission_required("site.manage_settings")
- def resolve_automatic_fulfillment_digital_products(self, info):
+ def resolve_automatic_fulfillment_digital_products(_, info):
site_settings = info.context.site.settings
return site_settings.automatic_fulfillment_digital_products
+ @staticmethod
@permission_required("site.manage_settings")
- def resolve_default_digital_max_downloads(self, info):
+ def resolve_default_digital_max_downloads(_, info):
return info.context.site.settings.default_digital_max_downloads
+ @staticmethod
@permission_required("site.manage_settings")
- def resolve_default_digital_url_valid_days(self, info):
+ def resolve_default_digital_url_valid_days(_, info):
return info.context.site.settings.default_digital_url_valid_days
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index eace3763c8..01cf47411c 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -21,17 +21,18 @@ class BaseTranslationType(CountableDjangoObjectType):
class Meta:
abstract = True
- def resolve_language(self, *_args):
+ @staticmethod
+ def resolve_language(root, *_args):
try:
language = next(
language[1]
for language in settings.LANGUAGES
- if language[0] == self.language_code
+ if language[0] == root.language_code
)
except StopIteration:
return None
return LanguageDisplay(
- code=LanguageCodeEnum[str_to_enum(self.language_code)], language=language
+ code=LanguageCodeEnum[str_to_enum(root.language_code)], language=language
)