Skip to content

Commit

Permalink
Allow filtering attribute values by ids (#9399)
Browse files Browse the repository at this point in the history
  • Loading branch information
IKarbowiak committed Mar 28, 2022
1 parent 80e94d3 commit 08b6645
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions saleor/graphql/attribute/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def filter_attribute_type(qs, _, value):

class AttributeValueFilter(django_filters.FilterSet):
search = django_filters.CharFilter(method="filter_search")
ids = GlobalIDMultipleChoiceFilter(field_name="id")

class Meta:
model = AttributeValue
Expand Down
23 changes: 23 additions & 0 deletions saleor/graphql/attribute/tests/queries/test_attribute_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ def test_filter_attributes_by_global_id_list(api_client, product_type_attribute_
assert received_slugs == expected_slugs


def test_filter_attribute_values_by_global_id_list(
api_client, attribute_choices_for_sorting
):
# given
values = attribute_choices_for_sorting.values.all()
global_ids = [
graphene.Node.to_global_id("AttributeValue", value.pk) for value in values[:2]
]
variables = {"filters": {"ids": global_ids}}

# when
content = get_graphql_content(
api_client.post_graphql(ATTRIBUTES_VALUE_FILTER_QUERY, variables)
)

# then
expected_slugs = sorted([values[0].slug, values[1].slug])
values = content["data"]["attributes"]["edges"][0]["node"]["choices"]["edges"]
assert len(values) == 2
received_slugs = sorted([value["node"]["slug"] for value in values])
assert received_slugs == expected_slugs


def test_filter_attributes_in_category_invalid_category_id(
user_api_client, product_list, weight_attribute, channel_USD
):
Expand Down
1 change: 1 addition & 0 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,7 @@ enum AttributeChoicesSortField {

input AttributeValueFilterInput {
search: String
ids: [ID!]
}

type AttributeTranslation implements Node {
Expand Down

0 comments on commit 08b6645

Please sign in to comment.