Skip to content

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

Change product collections, images and variants to a list in API

fowczarek86860210589e
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 2153eed7c4..72a7a657a2 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -275,9 +275,18 @@ class Product(CountableDjangoObjectType):
graphene.ID, description='ID of a product image.'),
description='Get a single product image by ID')
variants = gql_optimizer.field(
- PrefetchingConnectionField(ProductVariant), model_field='variants')
+ graphene.List(
+ ProductVariant, description='List of varinats for the product'),
+ model_field='variants')
images = gql_optimizer.field(
- PrefetchingConnectionField(lambda: ProductImage), model_field='images')
+ graphene.List(
+ ProductImage, description='List of images for the product'),
+ model_field='images')
+ collections = gql_optimizer.field(
+ graphene.List(
+ lambda: Collection,
+ description='List of collections for the product'),
+ model_field='collections')
class Meta:
description = dedent("""Represents an individual item for sale in the
@@ -335,6 +344,9 @@ class Product(CountableDjangoObjectType):
def resolve_variants(self, info, **kwargs):
return self.variants.all()
+ def resolve_collections(self, info):
+ return self.collections.all()
+
def prefetch_products(info, *args, **kwargs):
"""Prefetch products visible to the current user.
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 82e6644fe0..94ed44caea 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -90,19 +90,11 @@ def test_product_query(staff_api_client, product, permission_manage_products):
url
thumbnailUrl
images {
- edges {
- node {
- url
- }
- }
+ url
}
variants {
- edges {
- node {
- name
- stockQuantity
- }
- }
+ name
+ stockQuantity
}
availability {
available,
@@ -185,12 +177,8 @@ def test_product_with_collections(
query = """
query getProduct($productID: ID!) {
product(id: $productID) {
- collections(first: 1) {
- edges {
- node {
- name
- }
- }
+ collections {
+ name
}
}
}
@@ -204,8 +192,8 @@ def test_product_with_collections(
response = staff_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['product']
- assert data['collections']['edges'][0]['node']['name'] == collection.name
- assert len(data['collections']['edges']) == 1
+ assert data['collections'][0]['name'] == collection.name
+ assert len(data['collections']) == 1
def test_filter_product_by_category(user_api_client, product):
@@ -1198,12 +1186,8 @@ def test_product_variant_price(
query getProductVariants($id: ID!) {
product(id: $id) {
variants {
- edges {
- node {
- price {
- amount
- }
- }
+ price {
+ amount
}
}
}
@@ -1214,7 +1198,7 @@ def test_product_variant_price(
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['product']
- variant_price = data['variants']['edges'][0]['node']['price']
+ variant_price = data['variants'][0]['price']
assert variant_price['amount'] == api_variant_price