Repository: saleor/saleor

Issue:
Return flat attribute values list instead of connection
I just can't imagine a situation where anyone would need paginated attribute values list.


Discussion:
This issue is about turning product_attributes and variant_attributes on product type into a list. 

Resolving patch:
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -254,6 +254,10 @@ class ProductType(CountableDjangoObjectType):
         filterset_class=ProductFilterSet,
         description='List of products of this type.')
     tax_rate = TaxRateType(description='A type of tax rate.')
+    variant_attributes = graphene.List(
+        Attribute, description='Variant attributes of that product type.')
+    product_attributes = graphene.List(
+        Attribute, description='Product attributes of that product type.')
 
     class Meta:
         description = """Represents a type of product. It defines what
@@ -267,6 +271,12 @@ def resolve_products(self, info, **kwargs):
         return products_with_details(
             user=user).filter(product_type=self).distinct()
 
+    def resolve_variant_attributes(self, info):
+        return self.variant_attributes.prefetch_related('values')
+
+    def resolve_product_attributes(self, info):
+        return self.product_attributes.prefetch_related('values')
+
 
 class Collection(CountableDjangoObjectType):
     products = DjangoFilterConnectionField(


Test patch:
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -638,18 +638,16 @@ def test_product_type_create_mutation(admin_api_client, product_type):
             isShippingRequired
             hasVariants
             variantAttributes {
-                edges {
-                node {
+                name
+                values {
                     name
                 }
-                }
             }
             productAttributes {
-                edges {
-                node {
+                name
+                values {
                     name
                 }
-                }
             }
             }
         }
@@ -679,14 +677,23 @@ def test_product_type_create_mutation(admin_api_client, product_type):
     content = get_graphql_content(response)
     assert 'errors' not in content
     assert ProductType.objects.count() == initial_count + 1
-    data = content['data']['productTypeCreate']
-    assert data['productType']['name'] == product_type_name
-    assert data['productType']['hasVariants'] == has_variants
-    assert data['productType']['isShippingRequired'] == require_shipping
-    no_pa = product_attributes.count()
-    assert len(data['productType']['productAttributes']['edges']) == no_pa
-    no_va = variant_attributes.count()
-    assert len(data['productType']['variantAttributes']['edges']) == no_va
+    data = content['data']['productTypeCreate']['productType']
+    assert data['name'] == product_type_name
+    assert data['hasVariants'] == has_variants
+    assert data['isShippingRequired'] == require_shipping
+
+    pa = product_attributes[0]
+    assert data['productAttributes'][0]['name'] == pa.name
+    pa_values = data['productAttributes'][0]['values']
+    assert sorted([value['name'] for value in pa_values]) == sorted(
+        [value.name for value in pa.values.all()])
+
+    va = variant_attributes[0]
+    assert data['variantAttributes'][0]['name'] == va.name
+    va_values = data['variantAttributes'][0]['values']
+    assert sorted([value['name'] for value in va_values]) == sorted(
+        [value.name for value in va.values.all()])
+
     new_instance = ProductType.objects.latest('pk')
     assert new_instance.tax_rate == 'standard'
 
@@ -713,10 +720,10 @@ def test_product_type_update_mutation(admin_api_client, product_type):
                     isShippingRequired
                     hasVariants
                     variantAttributes {
-                        totalCount
+                        id
                     }
                     productAttributes {
-                        totalCount
+                        id
                     }
                 }
               }
@@ -745,13 +752,13 @@ def test_product_type_update_mutation(admin_api_client, product_type):
         reverse('api'), {'query': query, 'variables': variables})
     content = get_graphql_content(response)
     assert 'errors' not in content
-    data = content['data']['productTypeUpdate']
-    assert data['productType']['name'] == product_type_name
-    assert data['productType']['hasVariants'] == has_variants
-    assert data['productType']['isShippingRequired'] == require_shipping
-    assert data['productType']['productAttributes']['totalCount'] == 0
-    no_va = variant_attributes.count()
-    assert data['productType']['variantAttributes']['totalCount'] == no_va
+    data = content['data']['productTypeUpdate']['productType']
+    assert data['name'] == product_type_name
+    assert data['hasVariants'] == has_variants
+    assert data['isShippingRequired'] == require_shipping
+    assert len(data['productAttributes']) == 0
+    assert len(data['variantAttributes']) == (
+        variant_attributes.count())
 
 
 def test_product_type_delete_mutation(admin_api_client, product_type):