Repository: saleor/saleor
Pull request: Add ability to filter customers by ids
Add ids filter to customers endpoint
Fix [9523](https://github.com/saleor/saleor/issues/9523)

# Impact

* [ ] New migrations
* [ ] New/Updated API fields or mutations
* [ ] Deprecated API fields or mutations
* [ ] Removed API types, fields, or mutations
* [ ] Documentation needs to be updated

# Pull Request Checklist

<!-- Please keep this section. It will make the maintainer's life easier. -->

* [ ] Privileged queries and mutations are guarded by proper permission checks
* [ ] Database queries are optimized and the number of queries is constant
* [ ] Database migration files are up to date
* [ ] The changes are tested
* [ ] GraphQL schema and type definitions are up to date
* [ ] Changes are mentioned in the changelog


Problem statement:
add filter to get customers by id's.
### What I'm trying to achieve
Get customer by id.

### Describe a proposed solution
User/Programmer should be able to get customers based on customer/user id.

### Other solutions I've tried and won't work
We are able to get users by id, but In my case, I want to filter customers by a list of id's provided.

Hints from issue discussion:
+  +1 we need this too.
+2 We want this too.

Commit message: Add help text

Patch to review:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e865c343b5..164a93e997f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable, unreleased changes to this project will be documented in this file.
 - Add ability to filter by slug. #10578 by @kadewu
   - Affected types: Attribute, Category, Collection, Menu, Page, Product, ProductType, Warehouse
   - Deprecated `slug` in filter for `menus`. Use `slugs` instead
+- Add ability to filter customers by ids. #10694 by @kadewu
 
 ### Other changes
 
diff --git a/saleor/graphql/account/filters.py b/saleor/graphql/account/filters.py
index 3632808febe..885948cd827 100644
--- a/saleor/graphql/account/filters.py
+++ b/saleor/graphql/account/filters.py
@@ -3,6 +3,7 @@
 
 from ...account.models import User
 from ...account.search import search_users
+from ..core.descriptions import ADDED_IN_38
 from ..core.filters import (
     EnumFilter,
     GlobalIDMultipleChoiceFilter,
@@ -51,6 +52,9 @@ def filter_search(qs, _, value):
 
 
 class CustomerFilter(MetadataFilterBase):
+    ids = GlobalIDMultipleChoiceFilter(
+        field_name="id", help_text=f"Filter by ids {ADDED_IN_38}"
+    )
     date_joined = ObjectTypeFilter(
         input_class=DateRangeInput, method=filter_date_joined
     )
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index 6bec6db3d9e..a3380697448 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -5802,6 +5802,30 @@ def test_query_customer_members_with_filter_search(
     assert len(users) == count
 
 
+def test_query_customers_with_filter_by_ids(
+    query_customer_with_filter,
+    staff_api_client,
+    permission_manage_users,
+    customer_user,
+):
+    # given
+    variables = {
+        "filter": {
+            "ids": [graphene.Node.to_global_id("User", customer_user.pk)],
+        }
+    }
+
+    # when
+    response = staff_api_client.post_graphql(
+        query_customer_with_filter, variables, permissions=[permission_manage_users]
+    )
+    content = get_graphql_content(response)
+
+    # then
+    users = content["data"]["customers"]["edges"]
+    assert len(users) == 1
+
+
 @pytest.mark.parametrize(
     "staff_member_filter, count",
     [({"status": "DEACTIVATED"}, 1), ({"status": "ACTIVE"}, 2)],
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 3b3f5996c50..2a3a29a8001 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -10793,6 +10793,13 @@ input CustomerFilterInput {
   placedOrders: DateRangeInput
   search: String
   metadata: [MetadataFilter!]
+
+  """
+  Filter by ids 
+  
+  Added in Saleor 3.8.
+  """
+  ids: [ID!]
   updatedAt: DateTimeRangeInput
 }
 


Code review comments:
diff_hunk: @@ -51,6 +52,9 @@ def filter_search(qs, _, value):
 
 
 class CustomerFilter(MetadataFilterBase):
+    ids = GlobalIDMultipleChoiceFilter(
+        field_name="id", help_text=f"Filter by ids {ADDED_IN_38}"
path: saleor/graphql/account/filters.py
text: @user1:
👮‍♀️ 
```suggestion
        field_name="id", help_text=f"Filter by ids. {ADDED_IN_38}"
```

diff_hunk: @@ -5802,6 +5802,30 @@ def test_query_customer_members_with_filter_search(
     assert len(users) == count
 
 
+def test_query_customers_with_filter_by_ids(
+    query_customer_with_filter,
+    staff_api_client,
+    permission_manage_users,
+    customer_user,
+):
+    # given
+    variables = {
+        "filter": {
+            "ids": [graphene.Node.to_global_id("User", customer_user.pk)],
+        }
+    }
+
+    # when
+    response = staff_api_client.post_graphql(
+        query_customer_with_filter, variables, permissions=[permission_manage_users]
+    )
+    content = get_graphql_content(response)
+
+    # then
+    users = content["data"]["customers"]["edges"]
+    assert len(users) == 1
path: saleor/graphql/account/tests/test_account.py
text: @user1:
How do know that you get the correct user in response?