Skip to content

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

Fix review remarks

fowczareke7faf82ce8df
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index 89a6a3da3e..fc9a2f2297 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -39,10 +39,12 @@ class Checkout(CountableDjangoObjectType):
description='Shipping methods that can be used with this order.')
is_shipping_required = graphene.Boolean(
description='Returns True, if checkout requires shipping.')
- lines = graphene.List(
- CheckoutLine, description=(
- 'A list of checkout lines, each containing information about '
- 'an item in the checkout.'))
+ lines = gql_optimizer.field(
+ graphene.List(
+ CheckoutLine, description=(
+ 'A list of checkout lines, each containing information about '
+ 'an item in the checkout.')),
+ model_field='lines')
payments = gql_optimizer.field(
graphene.List(
Payment, description='List of payments for the checkout'),
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 72a7a657a2..f9cd76a939 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -129,28 +129,6 @@ class SelectedAttribute(graphene.ObjectType):
description = 'Represents a custom attribute.'
-class ProductImage(CountableDjangoObjectType):
- url = graphene.String(
- required=True,
- description='The URL of the image.',
- size=graphene.Int(description='Size of the image'))
-
- class Meta:
- description = 'Represents a product image.'
- exclude_fields = [
- 'image', 'product', 'ppoi', 'productvariant_set',
- 'variant_images']
- interfaces = [relay.Node]
- model = models.ProductImage
-
- def resolve_url(self, info, *, size=None):
- if size:
- url = get_thumbnail(self.image, size, method='thumbnail')
- else:
- url = self.image.url
- return info.context.build_absolute_uri(url)
-
-
class ProductVariant(CountableDjangoObjectType):
stock_quantity = graphene.Int(
required=True, description='Quantity of a product available for sale.')
@@ -175,7 +153,7 @@ class ProductVariant(CountableDjangoObjectType):
for such calculations.'''))
images = gql_optimizer.field(
graphene.List(
- ProductImage,
+ lambda: ProductImage,
description='List of images for the product variant'),
model_field='images')
@@ -280,7 +258,8 @@ class Product(CountableDjangoObjectType):
model_field='variants')
images = gql_optimizer.field(
graphene.List(
- ProductImage, description='List of images for the product'),
+ lambda: ProductImage,
+ description='List of images for the product'),
model_field='images')
collections = gql_optimizer.field(
graphene.List(
@@ -472,3 +451,25 @@ class Category(CountableDjangoObjectType):
qs = models.Product.objects.available_products()
qs = qs.filter(category__in=tree)
return gql_optimizer.query(qs, info)
+
+
+class ProductImage(CountableDjangoObjectType):
+ url = graphene.String(
+ required=True,
+ description='The URL of the image.',
+ size=graphene.Int(description='Size of the image'))
+
+ class Meta:
+ description = 'Represents a product image.'
+ exclude_fields = [
+ 'image', 'product', 'ppoi', 'productvariant_set',
+ 'variant_images']
+ interfaces = [relay.Node]
+ model = models.ProductImage
+
+ def resolve_url(self, info, *, size=None):
+ if size:
+ url = get_thumbnail(self.image, size, method='thumbnail')
+ else:
+ url = self.image.url
+ return info.context.build_absolute_uri(url)