Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add pagination for attributes values (#7341)
Damian Wysocki91a9ef775943
diff --git a/saleor/attribute/migrations/0011_attributevalue_attribute_a_name_9f3448_gin.py b/saleor/attribute/migrations/0011_attributevalue_attribute_a_name_9f3448_gin.pynew file mode 100644index 0000000000..7f66cfaf3d--- /dev/null+++ b/saleor/attribute/migrations/0011_attributevalue_attribute_a_name_9f3448_gin.py@@ -0,0 +1,20 @@+# Generated by Django 3.2.2 on 2021-05-19 08:13++import django.contrib.postgres.indexes+from django.db import migrations+++class Migration(migrations.Migration):++ dependencies = [+ ("attribute", "0010_auto_20210412_0736"),+ ]++ operations = [+ migrations.AddIndex(+ model_name="attributevalue",+ index=django.contrib.postgres.indexes.GinIndex(+ fields=["name", "slug"], name="attribute_a_name_9f3448_gin"+ ),+ ),+ ]diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.pyindex 0d82c43ab8..c81b6d9045 100644--- a/saleor/attribute/models/base.py+++ b/saleor/attribute/models/base.py@@ -1,5 +1,6 @@from typing import TYPE_CHECKING, Union+from django.contrib.postgres.indexes import GinIndexfrom django.db import modelsfrom django.db.models import F, Q@@ -205,6 +206,7 @@ class AttributeValue(SortableModel):class Meta:ordering = ("sort_order", "pk")unique_together = ("slug", "attribute")+ indexes = [GinIndex(fields=["name", "slug"])]def __str__(self) -> str:return self.namediff --git a/saleor/graphql/attribute/filters.py b/saleor/graphql/attribute/filters.pyindex 5f6a4fb8f0..826e927035 100644--- a/saleor/graphql/attribute/filters.py+++ b/saleor/graphql/attribute/filters.py@@ -3,12 +3,12 @@ from django.db.models import Qfrom graphene_django.filter import GlobalIDFilter, GlobalIDMultipleChoiceFilterfrom ...account.utils import requestor_is_staff_member_or_app-from ...attribute.models import Attribute+from ...attribute.models import Attribute, AttributeValuefrom ...product.models import Category, Productfrom ..attribute.enums import AttributeTypeEnumfrom ..channel.filters import get_channel_slug_from_filter_datafrom ..core.filters import EnumFilter, MetadataFilterBase-from ..core.types import ChannelFilterInputObjectType+from ..core.types import ChannelFilterInputObjectType, FilterInputObjectTypefrom ..core.utils import from_global_id_or_errorfrom ..utils import get_user_or_app_from_contextfrom ..utils.filters import filter_fields_containing_value@@ -58,6 +58,22 @@ def filter_attribute_type(qs, _, value):return qs.filter(type=value)+class AttributeValueFilter(django_filters.FilterSet):+ search = django_filters.CharFilter(method="filter_search")++ class Meta:+ model = AttributeValue+ fields = ["search"]++ @classmethod+ def filter_search(cls, queryset, _name, value):+ if not value:+ return queryset+ name_slug_qs = Q(name__trigram_similar=value) | Q(slug__trigram_similar=value)++ return queryset.filter(name_slug_qs)++class AttributeFilter(MetadataFilterBase):# Search by attribute name and slugsearch = django_filters.CharFilter(@@ -98,3 +114,8 @@ class AttributeFilter(MetadataFilterBase):class AttributeFilterInput(ChannelFilterInputObjectType):class Meta:filterset_class = AttributeFilter+++class AttributeValueFilterInput(FilterInputObjectType):+ class Meta:+ filterset_class = AttributeValueFilterdiff --git a/saleor/graphql/attribute/sorters.py b/saleor/graphql/attribute/sorters.pyindex 85beccc181..905d1417a2 100644--- a/saleor/graphql/attribute/sorters.py+++ b/saleor/graphql/attribute/sorters.py@@ -52,3 +52,24 @@ class AttributeSortingInput(SortInputObjectType):class Meta:sort_enum = AttributeSortFieldtype_name = "attributes"+++class AttributeChoicesSortField(graphene.Enum):+ NAME = ["name", "slug"]+ SLUG = ["slug"]++ @property+ def description(self):+ descriptions = {+ AttributeSortField.NAME.name: "Sort attribute choice by name.",+ AttributeSortField.SLUG.name: "Sort attribute choice by slug.",+ }+ if self.name in descriptions:+ return descriptions[self.name]+ raise ValueError("Unsupported enum value: %s" % self.value)+++class AttributeChoicesSortingInput(SortInputObjectType):+ class Meta:+ sort_enum = AttributeChoicesSortField+ type_name = "attribute choices"diff --git a/saleor/graphql/attribute/tests/benchmark/test_attribute.py b/saleor/graphql/attribute/tests/benchmark/test_attribute.pyindex 06e11f5c1b..02af7eef59 100644--- a/saleor/graphql/attribute/tests/benchmark/test_attribute.py+++ b/saleor/graphql/attribute/tests/benchmark/test_attribute.py@@ -20,9 +20,13 @@ def test_query_attribute(nameinputTypetype- values {- slug- inputType+ choices(first: 10) {+ edges {+ node {+ slug+ inputType+ }+ }}valueRequiredvisibleInStorefront@@ -62,9 +66,13 @@ def test_query_attributes(nameinputTypetype- values {- slug- inputType+ choices(first: 10) {+ edges {+ node {+ slug+ inputType+ }+ }}valueRequiredvisibleInStorefrontdiff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_create.py b/saleor/graphql/attribute/tests/mutations/test_attribute_create.pyindex 4833fa4246..36d91376ce 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_create.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_create.py@@ -27,10 +27,14 @@ CREATE_ATTRIBUTE_MUTATION = """filterableInDashboardavailableInGridstorefrontSearchPosition- values {- name- slug- value+ choices(first: 10) {+ edges {+ node {+ name+ slug+ value+ }+ }}productTypes(first: 10) {edges {@@ -89,11 +93,11 @@ def test_create_attribute_and_attribute_values(), "The attribute should not have been assigned to a product type"# Check if the attribute values were correctly created- assert len(data["attribute"]["values"]) == 1+ assert len(data["attribute"]["choices"]) == 1assert data["attribute"]["type"] == AttributeTypeEnum.PRODUCT_TYPE.name- assert data["attribute"]["values"][0]["name"] == name- assert data["attribute"]["values"][0]["slug"] == slugify(name)- assert data["attribute"]["values"][0]["value"] == value+ assert data["attribute"]["choices"]["edges"][0]["node"]["name"] == name+ assert data["attribute"]["choices"]["edges"][0]["node"]["slug"] == slugify(name)+ assert data["attribute"]["choices"]["edges"][0]["node"]["value"] == valuedef test_create_numeric_attribute_and_attribute_values(@@ -151,7 +155,7 @@ def test_create_numeric_attribute_and_attribute_values(assert data["attribute"]["filterableInDashboard"] is Trueassert data["attribute"]["availableInGrid"] is Trueassert data["attribute"]["storefrontSearchPosition"] == 0- assert data["attribute"]["values"] == []+ assert data["attribute"]["choices"]["edges"] == []def test_create_numeric_attribute_and_attribute_values_not_numeric_value_provided(@@ -240,7 +244,7 @@ def test_create_attribute_with_file_input_type(), "The attribute should not have been assigned to a product type"# Check if the attribute values were correctly created- assert len(data["attribute"]["values"]) == 0+ assert len(data["attribute"]["choices"]["edges"]) == 0assert data["attribute"]["type"] == AttributeTypeEnum.PRODUCT_TYPE.nameassert data["attribute"]["inputType"] == AttributeInputTypeEnum.FILE.name@@ -293,7 +297,7 @@ def test_create_attribute_with_reference_input_type(), "The attribute should not have been assigned to a product type"# Check if the attribute values were correctly created- assert len(data["attribute"]["values"]) == 0+ assert len(data["attribute"]["choices"]["edges"]) == 0assert data["attribute"]["type"] == AttributeTypeEnum.PRODUCT_TYPE.nameassert data["attribute"]["inputType"] == AttributeInputTypeEnum.REFERENCE.nameassert data["attribute"]["entityType"] == entity_type@@ -384,10 +388,10 @@ def test_create_page_attribute_and_attribute_values(assert data["attribute"]["storefrontSearchPosition"] == 0# Check if the attribute values were correctly created- assert len(data["attribute"]["values"]) == 1+ assert len(data["attribute"]["choices"]["edges"]) == 1assert data["attribute"]["type"] == AttributeTypeEnum.PAGE_TYPE.name- assert data["attribute"]["values"][0]["name"] == name- assert data["attribute"]["values"][0]["slug"] == slugify(name)+ assert data["attribute"]["choices"]["edges"][0]["node"]["name"] == name+ assert data["attribute"]["choices"]["edges"][0]["node"]["slug"] == slugify(name)def test_create_attribute_with_file_input_type_and_values(@@ -476,7 +480,7 @@ def test_create_attribute_with_file_input_type_correct_attribute_settings(), "The attribute should not have been assigned to a product type"# Check if the attribute values were correctly created- assert len(data["attribute"]["values"]) == 0+ assert len(data["attribute"]["choices"]["edges"]) == 0assert data["attribute"]["type"] == AttributeTypeEnum.PRODUCT_TYPE.nameassert data["attribute"]["inputType"] == AttributeInputTypeEnum.FILE.namediff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_reorder_values.py b/saleor/graphql/attribute/tests/mutations/test_attribute_reorder_values.pyindex e06af0167e..8ba728f9c4 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_reorder_values.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_reorder_values.py@@ -5,20 +5,24 @@ from ....tests.utils import get_graphql_contentATTRIBUTE_VALUES_REORDER_MUTATION = """mutation attributeReorderValues($attributeId: ID!, $moves: [ReorderInput]!) {- attributeReorderValues(attributeId: $attributeId, moves: $moves) {- attribute {- id- values {- id- }+ attributeReorderValues(attributeId: $attributeId, moves: $moves) {+ attribute {+ id+ choices(first: 10) {+ edges {+ node {+ id+ }+ }+ }+ }++ errors {+ field+ message}-- errors {- field- message- }- }}+}"""@@ -124,13 +128,13 @@ def test_sort_values_within_attribute(assert content["attribute"]["id"] == attribute_id- gql_values = content["attribute"]["values"]+ gql_values = content["attribute"]["choices"]["edges"]assert len(gql_values) == len(expected_order)actual_order = []for attr, expected_pk in zip(gql_values, expected_order):- gql_type, gql_attr_id = graphene.Node.from_global_id(attr["id"])+ gql_type, gql_attr_id = graphene.Node.from_global_id(attr["node"]["id"])assert gql_type == "AttributeValue"actual_order.append(int(gql_attr_id))diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_update.py b/saleor/graphql/attribute/tests/mutations/test_attribute_update.pyindex f3225d6248..e00a69a700 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_update.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_update.py@@ -22,9 +22,13 @@ UPDATE_ATTRIBUTE_MUTATION = """nameslugunit- values {- name- slug+ choices(first: 10) {+ edges {+ node {+ name+ slug+ }+ }}productTypes(first: 10) {edges {diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.pyindex 261e9d324f..507321b010 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py@@ -36,9 +36,13 @@ CREATE_ATTRIBUTE_VALUE_MUTATION = """code}attribute {- values {- name- value+ choices(first: 10) {+ edges {+ node {+ name+ value+ }+ }}}attributeValue {@@ -74,8 +78,12 @@ def test_create_attribute_value(attr_data = data["attributeValue"]assert attr_data["name"] == nameassert attr_data["slug"] == slugify(name)- assert name in [value["name"] for value in data["attribute"]["values"]]- assert value in [value["value"] for value in data["attribute"]["values"]]+ assert name in [+ value["node"]["name"] for value in data["attribute"]["choices"]["edges"]+ ]+ assert value in [+ value["node"]["value"] for value in data["attribute"]["choices"]["edges"]+ ]def test_create_attribute_value_not_unique_name(diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.pyindex 3fccb08644..3ad0631420 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py@@ -19,8 +19,12 @@ mutation AttributeValueUpdate(slug}attribute {- values {- name+ choices(first: 10) {+ edges {+ node {+ name+ }+ }}}}@@ -51,7 +55,9 @@ def test_update_attribute_value(value.refresh_from_db()assert data["attributeValue"]["name"] == name == value.nameassert data["attributeValue"]["slug"] == slugify(name)- assert name in [value["name"] for value in data["attribute"]["values"]]+ assert name in [+ value["node"]["name"] for value in data["attribute"]["choices"]["edges"]+ ]def test_update_attribute_value_name_not_unique(diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py b/saleor/graphql/attribute/tests/queries/test_attribute_filter.pyindex 30d9a72f62..251bff7411 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filter.py@@ -22,6 +22,27 @@ ATTRIBUTES_FILTER_QUERY = """}"""+ATTRIBUTES_VALUE_FILTER_QUERY = """+query($filters: AttributeValueFilterInput!) {+ attributes(first: 10) {+ edges {+ node {+ name+ slug+ choices(first: 10, filter: $filters) {+ edges {+ node {+ name+ slug+ }+ }+ }+ }+ }+ }+}+"""+def test_search_attributes(api_client, color_attribute, size_attribute):variables = {"filters": {"search": "color"}}@@ -34,6 +55,23 @@ def test_search_attributes(api_client, color_attribute, size_attribute):assert attributes[0]["node"]["slug"] == "color"+ "filter_value",+ ["red", "blue"],+)+def test_search_attributes_value(+ filter_value, api_client, color_attribute, size_attribute+):+ variables = {"filters": {"search": filter_value}}++ attributes = get_graphql_content(+ api_client.post_graphql(ATTRIBUTES_VALUE_FILTER_QUERY, variables)+ )+ values = attributes["data"]["attributes"]["edges"][0]["node"]["choices"]["edges"]+ assert len(values) == 1+ assert values[0]["node"]["slug"] == filter_value++def test_filter_attributes_if_filterable_in_dashboard(api_client, color_attribute, size_attribute):diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_query.py b/saleor/graphql/attribute/tests/queries/test_attribute_query.pyindex 62a64b7465..1e9a59b32a 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_query.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_query.py@@ -67,13 +67,18 @@ query($id: ID!) {entityTypetypeunit- values {- slug- inputType- file {- url- contentType+ choices(first: 10) {+ edges {+ node {+ slug+ inputType+ file {+ url+ contentType+ }+ }}+}valueRequiredvisibleInStorefront@@ -236,7 +241,7 @@ def test_get_single_product_attribute_with_file_value(attribute_data["storefrontSearchPosition"]== file_attribute.storefront_search_position)- assert attribute_data["values"] == []+ assert attribute_data["choices"]["edges"] == []def test_get_single_reference_attribute_by_staff(@@ -339,10 +344,14 @@ QUERY_ATTRIBUTES = """idnameslug- values {- id- name- slug+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ }+ }}}}diff --git a/saleor/graphql/attribute/tests/queries/test_attributes_sort.py b/saleor/graphql/attribute/tests/queries/test_attributes_sort.pyindex 0327c832bd..67d673b688 100644--- a/saleor/graphql/attribute/tests/queries/test_attributes_sort.py+++ b/saleor/graphql/attribute/tests/queries/test_attributes_sort.py@@ -146,3 +146,50 @@ def test_attributes_of_products_are_sorted(# Compare the received data against our expectationsassert actual_order == expected_order+++ATTRIBUTE_CHOICES_SORT_QUERY = """+query($sortBy: AttributeChoicesSortingInput) {+ attributes(first: 10) {+ edges {+ node {+ slug+ choices(first: 10, sortBy: $sortBy) {+ edges {+ node {+ name+ slug+ }+ }+ }+ }+ }+ }+}+"""+++def test_sort_attribute_choices_by_slug(api_client, attribute_choices_for_sorting):+ variables = {"sortBy": {"field": "SLUG", "direction": "ASC"}}+ attributes = get_graphql_content(+ api_client.post_graphql(ATTRIBUTE_CHOICES_SORT_QUERY, variables)+ )["data"]["attributes"]+ choices = attributes["edges"][0]["node"]["choices"]["edges"]++ assert len(choices) == 3+ assert choices[0]["node"]["slug"] == "absorb"+ assert choices[1]["node"]["slug"] == "summer"+ assert choices[2]["node"]["slug"] == "zet"+++def test_sort_attribute_choices_by_name(api_client, attribute_choices_for_sorting):+ variables = {"sortBy": {"field": "NAME", "direction": "ASC"}}+ attributes = get_graphql_content(+ api_client.post_graphql(ATTRIBUTE_CHOICES_SORT_QUERY, variables)+ )["data"]["attributes"]+ choices = attributes["edges"][0]["node"]["choices"]["edges"]++ assert len(choices) == 3+ assert choices[0]["node"]["name"] == "Apex"+ assert choices[1]["node"]["name"] == "Global"+ assert choices[2]["node"]["name"] == "Police"diff --git a/saleor/graphql/attribute/types.py b/saleor/graphql/attribute/types.pyindex d82b88d5f9..433c3201e4 100644--- a/saleor/graphql/attribute/types.py+++ b/saleor/graphql/attribute/types.py@@ -9,15 +9,18 @@ from ...core.tracing import traced_resolverfrom ...graphql.utils import get_user_or_app_from_contextfrom ..core.connection import CountableDjangoObjectTypefrom ..core.enums import MeasurementUnitsEnum+from ..core.fields import FilterInputConnectionFieldfrom ..core.types import Filefrom ..core.types.common import IntRangeInputfrom ..decorators import check_attribute_required_permissionsfrom ..meta.types import ObjectWithMetadatafrom ..translations.fields import TranslationFieldfrom ..translations.types import AttributeTranslation, AttributeValueTranslation-from .dataloaders import AttributesByAttributeId, AttributeValuesByAttributeIdLoader+from .dataloaders import AttributesByAttributeIdfrom .descriptions import AttributeDescriptions, AttributeValueDescriptionsfrom .enums import AttributeEntityTypeEnum, AttributeInputTypeEnum, AttributeTypeEnum+from .filters import AttributeValueFilterInput+from .sorters import AttributeChoicesSortingInputCOLOR_PATTERN = r"^(#[0-9a-fA-F]{3}|#(?:[0-9a-fA-F]{2}){2,4}|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))$" # noqacolor_pattern = re.compile(COLOR_PATTERN)@@ -99,8 +102,14 @@ class Attribute(CountableDjangoObjectType):slug = graphene.String(description=AttributeDescriptions.SLUG)type = AttributeTypeEnum(description=AttributeDescriptions.TYPE)unit = MeasurementUnitsEnum(description=AttributeDescriptions.UNIT)-- values = graphene.List(AttributeValue, description=AttributeDescriptions.VALUES)+ choices = FilterInputConnectionField(+ AttributeValue,+ sort_by=AttributeChoicesSortingInput(description="Sort attribute choices."),+ filter=AttributeValueFilterInput(+ description="Filtering options for attribute choices."+ ),+ description=AttributeDescriptions.VALUES,+ )value_required = graphene.Boolean(description=AttributeDescriptions.VALUE_REQUIRED, required=True@@ -135,9 +144,9 @@ class Attribute(CountableDjangoObjectType):@staticmethod@traced_resolver- def resolve_values(root: models.Attribute, info):+ def resolve_choices(root: models.Attribute, info, **_kwargs):if root.input_type in AttributeInputType.TYPES_WITH_CHOICES:- return AttributeValuesByAttributeIdLoader(info.context).load(root.id)+ return root.values.all()return []@staticmethoddiff --git a/saleor/graphql/core/tests/test_graphql.py b/saleor/graphql/core/tests/test_graphql.pyindex 71f62eeaf0..1b6311c0da 100644--- a/saleor/graphql/core/tests/test_graphql.py+++ b/saleor/graphql/core/tests/test_graphql.py@@ -197,11 +197,15 @@ def test_real_query(user_api_client, product, channel_USD):idnameslug- values {- id- name- slug- __typename+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ __typename+ }+ }}__typename}diff --git a/saleor/graphql/page/tests/benchmark/test_page_type.py b/saleor/graphql/page/tests/benchmark/test_page_type.pyindex 801dd89f63..ef01879618 100644--- a/saleor/graphql/page/tests/benchmark/test_page_type.py+++ b/saleor/graphql/page/tests/benchmark/test_page_type.py@@ -26,9 +26,13 @@ def test_query_page_type(nametypeinputType- values {- name- slug+ choices(first: 10) {+ edges {+ node {+ name+ slug+ }+ }}valueRequiredvisibleInStorefront@@ -41,9 +45,13 @@ def test_query_page_type(nametypeinputType- values {- name- slug+ choices(first: 10) {+ edges {+ node {+ name+ slug+ }+ }}valueRequiredvisibleInStorefront@@ -89,9 +97,13 @@ def test_query_page_types(nametypeinputType- values {- name- slug+ choices(first: 10) {+ edges {+ node {+ name+ slug+ }+ }}valueRequiredvisibleInStorefront@@ -104,9 +116,13 @@ def test_query_page_types(nametypeinputType- values {- name- slug+ choices(first: 10) {+ edges {+ node {+ name+ slug+ }+ }}valueRequiredvisibleInStorefrontdiff --git a/saleor/graphql/product/tests/benchmark/test_category.py b/saleor/graphql/product/tests/benchmark/test_category.pyindex 193b737257..8a84f2e468 100644--- a/saleor/graphql/product/tests/benchmark/test_category.py+++ b/saleor/graphql/product/tests/benchmark/test_category.py@@ -108,10 +108,14 @@ def test_category_view(api_client, category_with_products, count_queries, channeidnameslug- values {- id- name- slug+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ }+ }}}}diff --git a/saleor/graphql/product/tests/benchmark/test_collection.py b/saleor/graphql/product/tests/benchmark/test_collection.pyindex 1e8238f0fc..a0c9700f57 100644--- a/saleor/graphql/product/tests/benchmark/test_collection.py+++ b/saleor/graphql/product/tests/benchmark/test_collection.py@@ -93,10 +93,14 @@ def test_collection_view(api_client, published_collection, count_queries, channeidnameslug- values {- id- name- slug+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ }+ }}}}diff --git a/saleor/graphql/product/tests/benchmark/test_variant.py b/saleor/graphql/product/tests/benchmark/test_variant.pyindex c8d79954c3..5f42bd7603 100644--- a/saleor/graphql/product/tests/benchmark/test_variant.py+++ b/saleor/graphql/product/tests/benchmark/test_variant.py@@ -310,11 +310,15 @@ def test_update_product_variant(idnameslug- values {- id- name- slug- __typename+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ __typename+ }+ }}__typename}diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex 0671e9a5fe..3f4c13b143 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -291,8 +291,12 @@ query CollectionProducts($id: ID!,$channel: String, $filters: ProductFilterInputidattributes {attribute {- values {- slug+ choices(first: 10) {+ edges {+ node {+ slug+ }+ }}}}@@ -371,7 +375,16 @@ def test_filter_collection_products_by_multiple_attributes("Product", product_with_multiple_values_attributes.pk)assert product["attributes"] == [- {"attribute": {"values": [{"slug": "eco"}, {"slug": "power"}]}}+ {+ "attribute": {+ "choices": {+ "edges": [+ {"node": {"slug": "eco"}},+ {"node": {"slug": "power"}},+ ]+ }+ }+ }]diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex d31b3c5d26..ea15ec01d4 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -6534,15 +6534,24 @@ PRODUCT_TYPE_CREATE_MUTATION = """hasVariantsvariantAttributes {name- values {- name+ choices(first: 10) {+ edges {+ node {+ name+ }+ }}}productAttributes {name- values {- name- richText+ choices(first: 10) {+ edges {+ node {+ name+ richText+ }+ }+}}}@@ -6604,15 +6613,15 @@ def test_product_type_create_mutation(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(+ pa_values = data["productAttributes"][0]["choices"]["edges"]+ assert sorted([value["node"]["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(+ va_values = data["variantAttributes"][0]["choices"]["edges"]+ assert sorted([value["node"]["name"] for value in va_values]) == sorted([value.name for value in va.values.all()])@@ -6656,14 +6665,16 @@ def test_create_product_type_with_rich_text_attribute(expected_attributes = [{"name": "Color",- "values": [- {"name": "Red", "richText": None},- {"name": "Blue", "richText": None},- ],+ "choices": {+ "edges": [+ {"node": {"name": "Red", "richText": None}},+ {"node": {"name": "Blue", "richText": None}},+ ]+ },},{"name": "Text",- "values": [],+ "choices": {"edges": []},},]for attribute in data["productAttributes"]:diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.pyindex 028dbd600e..89fc12486f 100644--- a/saleor/graphql/product/tests/test_variant.py+++ b/saleor/graphql/product/tests/test_variant.py@@ -47,10 +47,14 @@ def test_fetch_variant(idnameslug- values {- id- name- slug+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ }+ }}}values {@@ -1321,11 +1325,15 @@ def test_product_variant_update_with_new_attributes(idnameslug- values {- id- name- slug- __typename+ choices(first:10) {+ edges {+ node {+ id+ name+ slug+ __typename+ }+ }}__typename}diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 650d86dc63..18777a2e71 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -413,7 +413,7 @@ type Attribute implements Node & ObjectWithMetadata {slug: Stringtype: AttributeTypeEnumunit: MeasurementUnitsEnum- values: [AttributeValue]+ choices(sortBy: AttributeChoicesSortingInput, filter: AttributeValueFilterInput, before: String, after: String, first: Int, last: Int): AttributeValueCountableConnectionvalueRequired: Boolean!visibleInStorefront: Boolean!filterableInStorefront: Boolean!@@ -429,6 +429,16 @@ type AttributeBulkDelete {errors: [AttributeError!]!}+enum AttributeChoicesSortField {+ NAME+ SLUG+}++input AttributeChoicesSortingInput {+ direction: OrderDirection!+ field: AttributeChoicesSortField!+}+type AttributeCountableConnection {pageInfo: PageInfo!edges: [AttributeCountableEdge!]!@@ -606,6 +616,17 @@ type AttributeValueBulkDelete {errors: [AttributeError!]!}+type AttributeValueCountableConnection {+ pageInfo: PageInfo!+ edges: [AttributeValueCountableEdge!]!+ totalCount: Int+}++type AttributeValueCountableEdge {+ node: AttributeValue!+ cursor: String!+}+type AttributeValueCreate {attribute: AttributeattributeErrors: [AttributeError!]! @deprecated(reason: "Use errors field instead. This field will be removed in Saleor 4.0.")@@ -626,6 +647,10 @@ type AttributeValueDelete {attributeValue: AttributeValue}+input AttributeValueFilterInput {+ search: String+}+input AttributeValueInput {id: IDvalues: [String]diff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.pyindex 9145b136e2..329e44defe 100644--- a/saleor/graphql/translations/tests/test_translations.py+++ b/saleor/graphql/translations/tests/test_translations.py@@ -414,12 +414,16 @@ def test_attribute_value_translation(user_api_client, pink_attribute_value):attributes(first: 1) {edges {node {- values {- translation(languageCode: PL) {- name- richText- language {- code+ choices(first: 10) {+ edges {+ node {+ translation(languageCode: PL) {+ name+ richText+ language {+ code+ }+ }}}}@@ -437,7 +441,9 @@ def test_attribute_value_translation(user_api_client, pink_attribute_value):)data = get_graphql_content(response)["data"]- attribute_value = data["attributes"]["edges"][0]["node"]["values"][-1]+ attribute_value = data["attributes"]["edges"][0]["node"]["choices"]["edges"][-1][+ "node"+ ]assert attribute_value["translation"]["name"] == "Różowy"assert attribute_value["translation"]["richText"] == json.dumps(dummy_editorjs("Pink")@@ -691,11 +697,15 @@ def test_attribute_value_no_translation(user_api_client, pink_attribute_value):attributes(first: 1) {edges {node {- values {- translation(languageCode: PL) {- name- language {- code+ choices(first: 10) {+ edges {+ node {+ translation(languageCode: PL) {+ name+ language {+ code+ }+ }}}}@@ -713,7 +723,9 @@ def test_attribute_value_no_translation(user_api_client, pink_attribute_value):)data = get_graphql_content(response)["data"]- attribute_value = data["attributes"]["edges"][0]["node"]["values"][-1]+ attribute_value = data["attributes"]["edges"][0]["node"]["choices"]["edges"][-1][+ "node"+ ]assert attribute_value["translation"] is Nonediff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 6008e6d9b4..f7e0cfee61 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -794,6 +794,22 @@ def color_attribute(db):return attribute+def attribute_choices_for_sorting(db):+ attribute = Attribute.objects.create(+ slug="sorting",+ name="Sorting",+ type=AttributeType.PRODUCT_TYPE,+ filterable_in_storefront=True,+ filterable_in_dashboard=True,+ available_in_grid=True,+ )+ AttributeValue.objects.create(attribute=attribute, name="Global", slug="summer")+ AttributeValue.objects.create(attribute=attribute, name="Apex", slug="zet")+ AttributeValue.objects.create(attribute=attribute, name="Police", slug="absorb")+ return attribute++@pytest.fixturedef rich_text_attribute(db):attribute = Attribute.objects.create(