Features: 1) Add type hinting to resolver methods in Order; 2) Improve resolve_payments_transactions to handle QuerySet access.
Fixes: 1) Add missing `QuerySet` import in `graphene/object_types.py`. Extra: 1) Minor refactoring for clarity in resolver method definitions.
This commit is contained in:
parent
ea236743ae
commit
07aadb5d83
1 changed files with 9 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from django.core.cache import cache
|
||||
from django.db.models import Max, Min
|
||||
from django.db.models import Max, Min, QuerySet
|
||||
from django.db.models.functions import Length
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from graphene import (
|
||||
|
|
@ -336,20 +336,22 @@ class OrderType(DjangoObjectType):
|
|||
)
|
||||
description = _("orders")
|
||||
|
||||
def resolve_total_price(self, _info):
|
||||
def resolve_total_price(self: Order, _info):
|
||||
return self.total_price
|
||||
|
||||
def resolve_total_quantity(self, _info):
|
||||
def resolve_total_quantity(self: Order, _info):
|
||||
return self.total_quantity
|
||||
|
||||
def resolve_notifications(self, _info):
|
||||
def resolve_notifications(self: Order, _info):
|
||||
return camelize(self.notifications)
|
||||
|
||||
def resolve_attributes(self, _info):
|
||||
def resolve_attributes(self: Order, _info):
|
||||
return camelize(self.attributes)
|
||||
|
||||
def resolve_payments_transactions(self, _info) -> None | Transaction:
|
||||
return None or self.payments_transactions
|
||||
def resolve_payments_transactions(self: Order, _info) -> QuerySet[Transaction] | None:
|
||||
if self.payments_transactions:
|
||||
return self.payments_transactions.all()
|
||||
return None
|
||||
|
||||
|
||||
class ProductImageType(DjangoObjectType):
|
||||
|
|
|
|||
Loading…
Reference in a new issue