prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Grapql query for home page
  ### What I'm trying to achieve
  I want to have a shop homepage which shows:
  * new arrivals,
  * product in a sale,
  * featured products,
  * featured collection,
  * categories links
  
  ### Describe a proposed solution
  ```graphql
  query HomePage {
    shop {
      featuredCollection {
        id
        name
      }
    }
    featured: products(first: 10, collectionSlug: "featured") {
      edges {
        node {
          id
          name
          thumbnailUrl
          category {
            id
            name
          }
          price {
            amount
            currency
          }
        }
      }
    }
    newArrivals: products(first: 10, sortBy: "creation_date") {
      edges {
        node {
          id
          name
          thumbnailUrl
          category {
            id
            name
          }
          price {
            amount
            currency
          }
        }
      }
    }
    sales: products(first: 10, collectionSlug: "sales") {
      edges {
        node {
          id
          name
          thumbnailUrl
          category {
            id
            name
          }
          price {
            amount
            currency
          }
        }
      }
    }
    categories {
      edges {
        node {
          id
          name
        }
      }
    }
  }
  
  ```
  
  ### Other solutions I've tried and won't work
  I introduced:
  * filter by collection slug for featured and sales. That is the simplest approach which I have in my mind.
  * exposing homepage collection in the shop query,
  * sorting products by creation data for new arrivals.
  
  This is only a proposition. If you have a better approach in mind please share it.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `saleor/product/filters.py`
  Content:
  ```
  1 from collections import OrderedDict
  2 
  3 from django.db.models import Q
  4 from django.forms import CheckboxSelectMultiple, ValidationError
  5 from django.utils.translation import pgettext_lazy
  6 from django_filters import MultipleChoiceFilter, OrderingFilter, RangeFilter
  7 
  8 from ..core.filters import SortedFilterSet
  9 from .models import Product, ProductAttribute
  10 
  11 SORT_BY_FIELDS = OrderedDict([
  12     ('name', pgettext_lazy('Product list sorting option', 'name')),
  13     ('price', pgettext_lazy('Product list sorting option', 'price'))])
  14 
  15 
  16 class ProductFilter(SortedFilterSet):
  17     sort_by = OrderingFilter(
  18         label=pgettext_lazy('Product list sorting form', 'Sort by'),
  19         fields=SORT_BY_FIELDS.keys(),
  20         field_labels=SORT_BY_FIELDS)
  21     price = RangeFilter(
  22         label=pgettext_lazy('Currency amount', 'Price'))
  23 
  24     class Meta:
  25         model = Product
  26         fields = []
  27 
  28     def __init__(self, *args, **kwargs):
  29         super().__init__(*args, **kwargs)
  30         self.product_attributes, self.variant_attributes = (
  31             self._get_attributes())
  32         self.filters.update(self._get_product_attributes_filters())
  33         self.filters.update(self._get_product_variants_attributes_filters())
  34         self.filters = OrderedDict(sorted(self.filters.items()))
  35 
  36     def _get_attributes(self):
  37         q_product_attributes = self._get_product_attributes_lookup()
  38         q_variant_attributes = self._get_variant_attributes_lookup()
  39         product_attributes = (
  40             ProductAttribute.objects.all()
  41             .prefetch_related('translations', 'values__translations')
  42             .filter(q_product_attributes)
  43             .distinct())
  44         variant_attributes = (
  45             ProductAttribute.objects.all()
  46             .prefetch_related('translations', 'values__translations')
  47             .filter(q_variant_attributes)
  48             .distinct())
  49         return product_attributes, variant_attributes
  50 
  51     def _get_product_attributes_lookup(self):
  52         raise NotImplementedError()
  53 
  54     def _get_variant_attributes_lookup(self):
  55         raise NotImplementedError()
  56 
  57     def _get_product_attributes_filters(self):
  58         filters = {}
  59         for attribute in self.product_attributes:
  60             filters[attribute.slug] = MultipleChoiceFilter(
  61                 name='attributes__%s' % attribute.pk,
  62                 label=attribute.translated.name,
  63                 widget=CheckboxSelectMultiple,
  64                 choices=self._get_attribute_choices(attribute))
  65         return filters
  66 
  67     def _get_product_variants_attributes_filters(self):
  68         filters = {}
  69         for attribute in self.variant_attributes:
  70             filters[attribute.slug] = MultipleChoiceFilter(
  71                 name='variants__attributes__%s' % attribute.pk,
  72                 label=attribute.translated.name,
  73                 widget=CheckboxSelectMultiple,
  74                 choices=self._get_attribute_choices(attribute))
  75         return filters
  76 
  77     def _get_attribute_choices(self, attribute):
  78         return [
  79             (choice.pk, choice.translated.name)
  80             for choice in attribute.values.all()]
  81 
  82     def validate_sort_by(self, value):
  83         if value.strip('-') not in SORT_BY_FIELDS:
  84             raise ValidationError(
  85                 pgettext_lazy(
  86                     'Validation error for sort_by filter',
  87                     '%(value)s is not a valid sorting option'),
  88                 params={'value': value})
  89 
  90 
  91 class ProductCategoryFilter(ProductFilter):
  92     def __init__(self, *args, **kwargs):
  93         self.category = kwargs.pop('category')
  94         super().__init__(*args, **kwargs)
  95 
  96     def _get_product_attributes_lookup(self):
  97         return Q(product_types__products__category=self.category)
  98 
  99     def _get_variant_attributes_lookup(self):
  100         return Q(product_variant_types__products__category=self.category)
  101 
  102 
  103 class ProductCollectionFilter(ProductFilter):
  104     def __init__(self, *args, **kwargs):
  105         self.collection = kwargs.pop('collection')
  106         super().__init__(*args, **kwargs)
  107 
  108     def _get_product_attributes_lookup(self):
  109         return Q(product_types__products__collections=self.collection)
  110 
  111     def _get_variant_attributes_lookup(self):
  112         return Q(product_variant_types__products__collections=self.collection)
  113
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/saleor/product/filters.py b/saleor/product/filters.py
  --- a/saleor/product/filters.py
  +++ b/saleor/product/filters.py
  @@ -10,7 +10,9 @@
   
   SORT_BY_FIELDS = OrderedDict([
       ('name', pgettext_lazy('Product list sorting option', 'name')),
  -    ('price', pgettext_lazy('Product list sorting option', 'price'))])
  +    ('price', pgettext_lazy('Product list sorting option', 'price')),
  +    ('updated_at', pgettext_lazy(
  +        'Product list sorting option', 'last updated'))])
   
   
   class ProductFilter(SortedFilterSet):
  
verification_info: {"golden_diff": "diff --git a/saleor/product/filters.py b/saleor/product/filters.py\n--- a/saleor/product/filters.py\n+++ b/saleor/product/filters.py\n@@ -10,7 +10,9 @@\n \n SORT_BY_FIELDS = OrderedDict([\n     ('name', pgettext_lazy('Product list sorting option', 'name')),\n-    ('price', pgettext_lazy('Product list sorting option', 'price'))])\n+    ('price', pgettext_lazy('Product list sorting option', 'price')),\n+    ('updated_at', pgettext_lazy(\n+        'Product list sorting option', 'last updated'))])\n \n \n class ProductFilter(SortedFilterSet):\n", "issue": "Grapql query for home page\n### What I'm trying to achieve\r\nI want to have a shop homepage which shows:\r\n* new arrivals,\r\n* product in a sale,\r\n* featured products,\r\n* featured collection,\r\n* categories links\r\n\r\n### Describe a proposed solution\r\n```graphql\r\nquery HomePage {\r\n  shop {\r\n    featuredCollection {\r\n      id\r\n      name\r\n    }\r\n  }\r\n  featured: products(first: 10, collectionSlug: \"featured\") {\r\n    edges {\r\n      node {\r\n        id\r\n        name\r\n        thumbnailUrl\r\n        category {\r\n          id\r\n          name\r\n        }\r\n        price {\r\n          amount\r\n          currency\r\n        }\r\n      }\r\n    }\r\n  }\r\n  newArrivals: products(first: 10, sortBy: \"creation_date\") {\r\n    edges {\r\n      node {\r\n        id\r\n        name\r\n        thumbnailUrl\r\n        category {\r\n          id\r\n          name\r\n        }\r\n        price {\r\n          amount\r\n          currency\r\n        }\r\n      }\r\n    }\r\n  }\r\n  sales: products(first: 10, collectionSlug: \"sales\") {\r\n    edges {\r\n      node {\r\n        id\r\n        name\r\n        thumbnailUrl\r\n        category {\r\n          id\r\n          name\r\n        }\r\n        price {\r\n          amount\r\n          currency\r\n        }\r\n      }\r\n    }\r\n  }\r\n  categories {\r\n    edges {\r\n      node {\r\n        id\r\n        name\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n```\r\n\r\n### Other solutions I've tried and won't work\r\nI introduced:\r\n* filter by collection slug for featured and sales. That is the simplest approach which I have in my mind.\r\n* exposing homepage collection in the shop query,\r\n* sorting products by creation data for new arrivals.\r\n\r\nThis is only a proposition. If you have a better approach in mind please share it.\n", "before_files": [{"content": "from collections import OrderedDict\n\nfrom django.db.models import Q\nfrom django.forms import CheckboxSelectMultiple, ValidationError\nfrom django.utils.translation import pgettext_lazy\nfrom django_filters import MultipleChoiceFilter, OrderingFilter, RangeFilter\n\nfrom ..core.filters import SortedFilterSet\nfrom .models import Product, ProductAttribute\n\nSORT_BY_FIELDS = OrderedDict([\n    ('name', pgettext_lazy('Product list sorting option', 'name')),\n    ('price', pgettext_lazy('Product list sorting option', 'price'))])\n\n\nclass ProductFilter(SortedFilterSet):\n    sort_by = OrderingFilter(\n        label=pgettext_lazy('Product list sorting form', 'Sort by'),\n        fields=SORT_BY_FIELDS.keys(),\n        field_labels=SORT_BY_FIELDS)\n    price = RangeFilter(\n        label=pgettext_lazy('Currency amount', 'Price'))\n\n    class Meta:\n        model = Product\n        fields = []\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.product_attributes, self.variant_attributes = (\n            self._get_attributes())\n        self.filters.update(self._get_product_attributes_filters())\n        self.filters.update(self._get_product_variants_attributes_filters())\n        self.filters = OrderedDict(sorted(self.filters.items()))\n\n    def _get_attributes(self):\n        q_product_attributes = self._get_product_attributes_lookup()\n        q_variant_attributes = self._get_variant_attributes_lookup()\n        product_attributes = (\n            ProductAttribute.objects.all()\n            .prefetch_related('translations', 'values__translations')\n            .filter(q_product_attributes)\n            .distinct())\n        variant_attributes = (\n            ProductAttribute.objects.all()\n            .prefetch_related('translations', 'values__translations')\n            .filter(q_variant_attributes)\n            .distinct())\n        return product_attributes, variant_attributes\n\n    def _get_product_attributes_lookup(self):\n        raise NotImplementedError()\n\n    def _get_variant_attributes_lookup(self):\n        raise NotImplementedError()\n\n    def _get_product_attributes_filters(self):\n        filters = {}\n        for attribute in self.product_attributes:\n            filters[attribute.slug] = MultipleChoiceFilter(\n                name='attributes__%s' % attribute.pk,\n                label=attribute.translated.name,\n                widget=CheckboxSelectMultiple,\n                choices=self._get_attribute_choices(attribute))\n        return filters\n\n    def _get_product_variants_attributes_filters(self):\n        filters = {}\n        for attribute in self.variant_attributes:\n            filters[attribute.slug] = MultipleChoiceFilter(\n                name='variants__attributes__%s' % attribute.pk,\n                label=attribute.translated.name,\n                widget=CheckboxSelectMultiple,\n                choices=self._get_attribute_choices(attribute))\n        return filters\n\n    def _get_attribute_choices(self, attribute):\n        return [\n            (choice.pk, choice.translated.name)\n            for choice in attribute.values.all()]\n\n    def validate_sort_by(self, value):\n        if value.strip('-') not in SORT_BY_FIELDS:\n            raise ValidationError(\n                pgettext_lazy(\n                    'Validation error for sort_by filter',\n                    '%(value)s is not a valid sorting option'),\n                params={'value': value})\n\n\nclass ProductCategoryFilter(ProductFilter):\n    def __init__(self, *args, **kwargs):\n        self.category = kwargs.pop('category')\n        super().__init__(*args, **kwargs)\n\n    def _get_product_attributes_lookup(self):\n        return Q(product_types__products__category=self.category)\n\n    def _get_variant_attributes_lookup(self):\n        return Q(product_variant_types__products__category=self.category)\n\n\nclass ProductCollectionFilter(ProductFilter):\n    def __init__(self, *args, **kwargs):\n        self.collection = kwargs.pop('collection')\n        super().__init__(*args, **kwargs)\n\n    def _get_product_attributes_lookup(self):\n        return Q(product_types__products__collections=self.collection)\n\n    def _get_variant_attributes_lookup(self):\n        return Q(product_variant_types__products__collections=self.collection)\n", "path": "saleor/product/filters.py"}], "after_files": [{"content": "from collections import OrderedDict\n\nfrom django.db.models import Q\nfrom django.forms import CheckboxSelectMultiple, ValidationError\nfrom django.utils.translation import pgettext_lazy\nfrom django_filters import MultipleChoiceFilter, OrderingFilter, RangeFilter\n\nfrom ..core.filters import SortedFilterSet\nfrom .models import Product, ProductAttribute\n\nSORT_BY_FIELDS = OrderedDict([\n    ('name', pgettext_lazy('Product list sorting option', 'name')),\n    ('price', pgettext_lazy('Product list sorting option', 'price')),\n    ('updated_at', pgettext_lazy(\n        'Product list sorting option', 'last updated'))])\n\n\nclass ProductFilter(SortedFilterSet):\n    sort_by = OrderingFilter(\n        label=pgettext_lazy('Product list sorting form', 'Sort by'),\n        fields=SORT_BY_FIELDS.keys(),\n        field_labels=SORT_BY_FIELDS)\n    price = RangeFilter(\n        label=pgettext_lazy('Currency amount', 'Price'))\n\n    class Meta:\n        model = Product\n        fields = []\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.product_attributes, self.variant_attributes = (\n            self._get_attributes())\n        self.filters.update(self._get_product_attributes_filters())\n        self.filters.update(self._get_product_variants_attributes_filters())\n        self.filters = OrderedDict(sorted(self.filters.items()))\n\n    def _get_attributes(self):\n        q_product_attributes = self._get_product_attributes_lookup()\n        q_variant_attributes = self._get_variant_attributes_lookup()\n        product_attributes = (\n            ProductAttribute.objects.all()\n            .prefetch_related('translations', 'values__translations')\n            .filter(q_product_attributes)\n            .distinct())\n        variant_attributes = (\n            ProductAttribute.objects.all()\n            .prefetch_related('translations', 'values__translations')\n            .filter(q_variant_attributes)\n            .distinct())\n        return product_attributes, variant_attributes\n\n    def _get_product_attributes_lookup(self):\n        raise NotImplementedError()\n\n    def _get_variant_attributes_lookup(self):\n        raise NotImplementedError()\n\n    def _get_product_attributes_filters(self):\n        filters = {}\n        for attribute in self.product_attributes:\n            filters[attribute.slug] = MultipleChoiceFilter(\n                name='attributes__%s' % attribute.pk,\n                label=attribute.translated.name,\n                widget=CheckboxSelectMultiple,\n                choices=self._get_attribute_choices(attribute))\n        return filters\n\n    def _get_product_variants_attributes_filters(self):\n        filters = {}\n        for attribute in self.variant_attributes:\n            filters[attribute.slug] = MultipleChoiceFilter(\n                name='variants__attributes__%s' % attribute.pk,\n                label=attribute.translated.name,\n                widget=CheckboxSelectMultiple,\n                choices=self._get_attribute_choices(attribute))\n        return filters\n\n    def _get_attribute_choices(self, attribute):\n        return [\n            (choice.pk, choice.translated.name)\n            for choice in attribute.values.all()]\n\n    def validate_sort_by(self, value):\n        if value.strip('-') not in SORT_BY_FIELDS:\n            raise ValidationError(\n                pgettext_lazy(\n                    'Validation error for sort_by filter',\n                    '%(value)s is not a valid sorting option'),\n                params={'value': value})\n\n\nclass ProductCategoryFilter(ProductFilter):\n    def __init__(self, *args, **kwargs):\n        self.category = kwargs.pop('category')\n        super().__init__(*args, **kwargs)\n\n    def _get_product_attributes_lookup(self):\n        return Q(product_types__products__category=self.category)\n\n    def _get_variant_attributes_lookup(self):\n        return Q(product_variant_types__products__category=self.category)\n\n\nclass ProductCollectionFilter(ProductFilter):\n    def __init__(self, *args, **kwargs):\n        self.collection = kwargs.pop('collection')\n        super().__init__(*args, **kwargs)\n\n    def _get_product_attributes_lookup(self):\n        return Q(product_types__products__collections=self.collection)\n\n    def _get_variant_attributes_lookup(self):\n        return Q(product_variant_types__products__collections=self.collection)\n", "path": "saleor/product/filters.py"}]}