We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add viewer query
With PR #3202 we've added ability to get the data of currently logged in user with the `user` query. I would recommend refactoring it a little bit and introducing a separate query for that. The problem with the `user` query is that it expects the `ID!` argument, but it also accepts passing `""` as ID value to resolve the logged in user. This brakes the single-responsibility rule (which is a good practice for GraphQL queries), is a bit unintuitive and makes to code harder to maintain.

I would propose changing the schema to have the following queries:
`viewer: User` - returns currently authenticated user
`user(id: ID!): User` - resolves a user by ID, where ID is required

--- 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/graphql/account/resolvers.py`
Content:
```
1 import graphene
2 import graphene_django_optimizer as gql_optimizer
3 from django.db.models import Q
4 from i18naddress import get_validation_rules
5 
6 from ...account import models
7 from ...core.utils import get_client_ip, get_country_by_ip
8 from ..utils import filter_by_query_param
9 from .types import AddressValidationData, ChoiceValue, User
10 
11 USER_SEARCH_FIELDS = (
12     'email', 'default_shipping_address__first_name',
13     'default_shipping_address__last_name', 'default_shipping_address__city',
14     'default_shipping_address__country')
15 
16 
17 def resolve_user(info, id):
18     logged_user = info.context.user
19     if not id:
20         return logged_user
21     user = graphene.Node.get_node_from_global_id(info, id, User)
22     if logged_user.has_perm('account.manage_users') or user == logged_user:
23         return user
24     return None
25 
26 
27 def resolve_customers(info, query):
28     qs = models.User.objects.filter(
29         Q(is_staff=False) | (Q(is_staff=True) & Q(orders__isnull=False)))
30     qs = filter_by_query_param(
31         queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)
32     qs = qs.order_by('email')
33     qs = qs.distinct()
34     return gql_optimizer.query(qs, info)
35 
36 
37 def resolve_staff_users(info, query):
38     qs = models.User.objects.filter(is_staff=True)
39     qs = filter_by_query_param(
40         queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)
41     qs = qs.order_by('email')
42     qs = qs.distinct()
43     return gql_optimizer.query(qs, info)
44 
45 
46 def resolve_address_validator(info, input):
47     country_code = input['country_code']
48     if not country_code:
49         client_ip = get_client_ip(info.context)
50         country = get_country_by_ip(client_ip)
51         if country:
52             country_code = country.code
53         else:
54             return None
55     params = {
56         'country_code': country_code,
57         'country_area': input['country_area'],
58         'city_area': input['city_area']}
59     rules = get_validation_rules(params)
60     return AddressValidationData(
61         country_code=rules.country_code,
62         country_name=rules.country_name,
63         address_format=rules.address_format,
64         address_latin_format=rules.address_latin_format,
65         allowed_fields=rules.allowed_fields,
66         required_fields=rules.required_fields,
67         upper_fields=rules.upper_fields,
68         country_area_type=rules.country_area_type,
69         country_area_choices=[
70             ChoiceValue(area[0], area[1])
71             for area in rules.country_area_choices],
72         city_type=rules.city_type,
73         city_area_choices=[
74             ChoiceValue(area[0], area[1]) for area in rules.city_area_choices],
75         postal_code_type=rules.postal_code_type,
76         postal_code_matchers=[
77             compiled.pattern for compiled in rules.postal_code_matchers],
78         postal_code_examples=rules.postal_code_examples,
79         postal_code_prefix=rules.postal_code_prefix)
80
```

Path: `saleor/graphql/account/types.py`
Content:
```
1 import graphene
2 import graphene_django_optimizer as gql_optimizer
3 from django.contrib.auth import get_user_model
4 from graphene import relay
5 
6 from ...account import models
7 from ...core.permissions import get_permissions
8 from ..core.types.common import (
9     CountableDjangoObjectType, CountryDisplay, PermissionDisplay)
10 from ..utils import format_permissions_for_display
11 
12 
13 class AddressInput(graphene.InputObjectType):
14     first_name = graphene.String(description='Given name.')
15     last_name = graphene.String(description='Family name.')
16     company_name = graphene.String(description='Company or organization.')
17     street_address_1 = graphene.String(description='Address.')
18     street_address_2 = graphene.String(description='Address.')
19     city = graphene.String(description='City.')
20     city_area = graphene.String(description='District.')
21     postal_code = graphene.String(description='Postal code.')
22     country = graphene.String(required=True, description='Country.')
23     country_area = graphene.String(description='State or province.')
24     phone = graphene.String(description='Phone number.')
25 
26 
27 class Address(CountableDjangoObjectType):
28     country = graphene.Field(
29         CountryDisplay, required=True, description='Default shop\'s country')
30 
31     class Meta:
32         exclude_fields = ['user_set', 'user_addresses']
33         description = 'Represents user address data.'
34         interfaces = [relay.Node]
35         model = models.Address
36 
37     def resolve_country(self, info):
38         return CountryDisplay(
39             code=self.country.code, country=self.country.name)
40 
41 
42 class User(CountableDjangoObjectType):
43     permissions = graphene.List(
44         PermissionDisplay, description='List of user\'s permissions.')
45     addresses = gql_optimizer.field(
46         graphene.List(
47             Address, description='List of all user\'s addresses.'),
48         model_field='addresses')
49 
50     class Meta:
51         exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']
52         description = 'Represents user data.'
53         interfaces = [relay.Node]
54         model = get_user_model()
55 
56     def resolve_permissions(self, info, **kwargs):
57         if self.is_superuser:
58             permissions = get_permissions()
59         else:
60             permissions = self.user_permissions.prefetch_related(
61                 'content_type').order_by('codename')
62         return format_permissions_for_display(permissions)
63 
64     def resolve_addresses(self, info, **kwargs):
65         return self.addresses.all()
66 
67 
68 class AddressValidationInput(graphene.InputObjectType):
69     country_code = graphene.String()
70     country_area = graphene.String()
71     city_area = graphene.String()
72 
73 
74 class ChoiceValue(graphene.ObjectType):
75     raw = graphene.String()
76     verbose = graphene.String()
77 
78 
79 class AddressValidationData(graphene.ObjectType):
80     country_code = graphene.String()
81     country_name = graphene.String()
82     address_format = graphene.String()
83     address_latin_format = graphene.String()
84     allowed_fields = graphene.List(graphene.String)
85     required_fields = graphene.List(graphene.String)
86     upper_fields = graphene.List(graphene.String)
87     country_area_type = graphene.String()
88     country_area_choices = graphene.List(ChoiceValue)
89     city_type = graphene.String()
90     city_area_choices = graphene.List(ChoiceValue)
91     postal_code_type = graphene.String()
92     postal_code_matchers = graphene.List(graphene.String)
93     postal_code_examples = graphene.List(graphene.String)
94     postal_code_prefix = graphene.String()
95
```

Path: `saleor/graphql/account/schema.py`
Content:
```
1 import graphene
2 from graphql_jwt.decorators import login_required, permission_required
3 
4 from ..core.fields import PrefetchingConnectionField
5 from ..descriptions import DESCRIPTIONS
6 from .mutations import (
7     AddressCreate, AddressDelete, AddressUpdate, CustomerCreate,
8     CustomerDelete, CustomerPasswordReset, CustomerRegister, CustomerUpdate,
9     LoggedUserUpdate, PasswordReset, SetPassword, StaffCreate, StaffDelete,
10     StaffUpdate)
11 from .resolvers import (
12     resolve_address_validator, resolve_customers, resolve_staff_users,
13     resolve_user)
14 from .types import AddressValidationData, AddressValidationInput, User
15 
16 
17 class AccountQueries(graphene.ObjectType):
18     address_validator = graphene.Field(
19         AddressValidationData,
20         input=graphene.Argument(AddressValidationInput, required=True))
21     customers = PrefetchingConnectionField(
22         User, description='List of the shop\'s customers.',
23         query=graphene.String(description=DESCRIPTIONS['user']))
24     staff_users = PrefetchingConnectionField(
25         User, description='List of the shop\'s staff users.',
26         query=graphene.String(description=DESCRIPTIONS['user']))
27     user = graphene.Field(
28         User, id=graphene.Argument(graphene.ID, required=True),
29         description='Lookup an user by ID.')
30 
31     def resolve_address_validator(self, info, input):
32         return resolve_address_validator(info, input)
33 
34     @permission_required('account.manage_users')
35     def resolve_customers(self, info, query=None, **kwargs):
36         return resolve_customers(info, query=query)
37 
38     @permission_required('account.manage_staff')
39     def resolve_staff_users(self, info, query=None, **kwargs):
40         return resolve_staff_users(info, query=query)
41 
42     @login_required
43     def resolve_user(self, info, id):
44         return resolve_user(info, id)
45 
46 
47 class AccountMutations(graphene.ObjectType):
48     password_reset = PasswordReset.Field()
49     set_password = SetPassword.Field()
50 
51     customer_create = CustomerCreate.Field()
52     customer_delete = CustomerDelete.Field()
53     customer_password_reset = CustomerPasswordReset.Field()
54     customer_register = CustomerRegister.Field()
55     customer_update = CustomerUpdate.Field()
56 
57     logged_user_update = LoggedUserUpdate.Field()
58 
59     staff_create = StaffCreate.Field()
60     staff_delete = StaffDelete.Field()
61     staff_update = StaffUpdate.Field()
62 
63     address_create = AddressCreate.Field()
64     address_delete = AddressDelete.Field()
65     address_update = AddressUpdate.Field()
66
```
--- 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()

```

diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py
--- a/saleor/graphql/account/resolvers.py
+++ b/saleor/graphql/account/resolvers.py
@@ -1,4 +1,3 @@
-import graphene
 import graphene_django_optimizer as gql_optimizer
 from django.db.models import Q
 from i18naddress import get_validation_rules
@@ -6,7 +5,7 @@
 from ...account import models
 from ...core.utils import get_client_ip, get_country_by_ip
 from ..utils import filter_by_query_param
-from .types import AddressValidationData, ChoiceValue, User
+from .types import AddressValidationData, ChoiceValue
 
 USER_SEARCH_FIELDS = (
     'email', 'default_shipping_address__first_name',
@@ -14,16 +13,6 @@
     'default_shipping_address__country')
 
 
-def resolve_user(info, id):
-    logged_user = info.context.user
-    if not id:
-        return logged_user
-    user = graphene.Node.get_node_from_global_id(info, id, User)
-    if logged_user.has_perm('account.manage_users') or user == logged_user:
-        return user
-    return None
-
-
 def resolve_customers(info, query):
     qs = models.User.objects.filter(
         Q(is_staff=False) | (Q(is_staff=True) & Q(orders__isnull=False)))
diff --git a/saleor/graphql/account/schema.py b/saleor/graphql/account/schema.py
--- a/saleor/graphql/account/schema.py
+++ b/saleor/graphql/account/schema.py
@@ -9,8 +9,7 @@
     LoggedUserUpdate, PasswordReset, SetPassword, StaffCreate, StaffDelete,
     StaffUpdate)
 from .resolvers import (
-    resolve_address_validator, resolve_customers, resolve_staff_users,
-    resolve_user)
+    resolve_address_validator, resolve_customers, resolve_staff_users)
 from .types import AddressValidationData, AddressValidationInput, User
 
 
@@ -21,6 +20,8 @@
     customers = PrefetchingConnectionField(
         User, description='List of the shop\'s customers.',
         query=graphene.String(description=DESCRIPTIONS['user']))
+    me = graphene.Field(
+        User, description='Logged in user data.')
     staff_users = PrefetchingConnectionField(
         User, description='List of the shop\'s staff users.',
         query=graphene.String(description=DESCRIPTIONS['user']))
@@ -35,13 +36,17 @@
     def resolve_customers(self, info, query=None, **kwargs):
         return resolve_customers(info, query=query)
 
+    @login_required
+    def resolve_me(self, info):
+        return info.context.user
+
     @permission_required('account.manage_staff')
     def resolve_staff_users(self, info, query=None, **kwargs):
         return resolve_staff_users(info, query=query)
 
-    @login_required
+    @permission_required('account.manage_users')
     def resolve_user(self, info, id):
-        return resolve_user(info, id)
+        return graphene.Node.get_node_from_global_id(info, id, User)
 
 
 class AccountMutations(graphene.ObjectType):
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -2,6 +2,7 @@
 import graphene_django_optimizer as gql_optimizer
 from django.contrib.auth import get_user_model
 from graphene import relay
+from graphql_jwt.decorators import permission_required
 
 from ...account import models
 from ...core.permissions import get_permissions
@@ -47,6 +48,7 @@
         PrefetchingConnectionField(
             Address, description='List of all user\'s addresses.'),
         model_field='addresses')
+    note = graphene.String(description='A note about the customer')
 
     class Meta:
         exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']
@@ -65,6 +67,10 @@
     def resolve_addresses(self, info, **kwargs):
         return self.addresses.all()
 
+    @permission_required('account.manage_users')
+    def resolve_note(self, info):
+        return self.note
+
 
 class AddressValidationInput(graphene.InputObjectType):
     country_code = graphene.String()

{"golden_diff": "diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py\n--- a/saleor/graphql/account/resolvers.py\n+++ b/saleor/graphql/account/resolvers.py\n@@ -1,4 +1,3 @@\n-import graphene\n import graphene_django_optimizer as gql_optimizer\n from django.db.models import Q\n from i18naddress import get_validation_rules\n@@ -6,7 +5,7 @@\n from ...account import models\n from ...core.utils import get_client_ip, get_country_by_ip\n from ..utils import filter_by_query_param\n-from .types import AddressValidationData, ChoiceValue, User\n+from .types import AddressValidationData, ChoiceValue\n \n USER_SEARCH_FIELDS = (\n     'email', 'default_shipping_address__first_name',\n@@ -14,16 +13,6 @@\n     'default_shipping_address__country')\n \n \n-def resolve_user(info, id):\n-    logged_user = info.context.user\n-    if not id:\n-        return logged_user\n-    user = graphene.Node.get_node_from_global_id(info, id, User)\n-    if logged_user.has_perm('account.manage_users') or user == logged_user:\n-        return user\n-    return None\n-\n-\n def resolve_customers(info, query):\n     qs = models.User.objects.filter(\n         Q(is_staff=False) | (Q(is_staff=True) & Q(orders__isnull=False)))\ndiff --git a/saleor/graphql/account/schema.py b/saleor/graphql/account/schema.py\n--- a/saleor/graphql/account/schema.py\n+++ b/saleor/graphql/account/schema.py\n@@ -9,8 +9,7 @@\n     LoggedUserUpdate, PasswordReset, SetPassword, StaffCreate, StaffDelete,\n     StaffUpdate)\n from .resolvers import (\n-    resolve_address_validator, resolve_customers, resolve_staff_users,\n-    resolve_user)\n+    resolve_address_validator, resolve_customers, resolve_staff_users)\n from .types import AddressValidationData, AddressValidationInput, User\n \n \n@@ -21,6 +20,8 @@\n     customers = PrefetchingConnectionField(\n         User, description='List of the shop\\'s customers.',\n         query=graphene.String(description=DESCRIPTIONS['user']))\n+    me = graphene.Field(\n+        User, description='Logged in user data.')\n     staff_users = PrefetchingConnectionField(\n         User, description='List of the shop\\'s staff users.',\n         query=graphene.String(description=DESCRIPTIONS['user']))\n@@ -35,13 +36,17 @@\n     def resolve_customers(self, info, query=None, **kwargs):\n         return resolve_customers(info, query=query)\n \n+    @login_required\n+    def resolve_me(self, info):\n+        return info.context.user\n+\n     @permission_required('account.manage_staff')\n     def resolve_staff_users(self, info, query=None, **kwargs):\n         return resolve_staff_users(info, query=query)\n \n-    @login_required\n+    @permission_required('account.manage_users')\n     def resolve_user(self, info, id):\n-        return resolve_user(info, id)\n+        return graphene.Node.get_node_from_global_id(info, id, User)\n \n \n class AccountMutations(graphene.ObjectType):\ndiff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py\n--- a/saleor/graphql/account/types.py\n+++ b/saleor/graphql/account/types.py\n@@ -2,6 +2,7 @@\n import graphene_django_optimizer as gql_optimizer\n from django.contrib.auth import get_user_model\n from graphene import relay\n+from graphql_jwt.decorators import permission_required\n \n from ...account import models\n from ...core.permissions import get_permissions\n@@ -47,6 +48,7 @@\n         PrefetchingConnectionField(\n             Address, description='List of all user\\'s addresses.'),\n         model_field='addresses')\n+    note = graphene.String(description='A note about the customer')\n \n     class Meta:\n         exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']\n@@ -65,6 +67,10 @@\n     def resolve_addresses(self, info, **kwargs):\n         return self.addresses.all()\n \n+    @permission_required('account.manage_users')\n+    def resolve_note(self, info):\n+        return self.note\n+\n \n class AddressValidationInput(graphene.InputObjectType):\n     country_code = graphene.String()\n", "issue": "Add viewer query\nWith PR #3202 we've added ability to get the data of currently logged in user with the `user` query. I would recommend refactoring it a little bit and introducing a separate query for that. The problem with the `user` query is that it expects the `ID!` argument, but it also accepts passing `\"\"` as ID value to resolve the logged in user. This brakes the single-responsibility rule (which is a good practice for GraphQL queries), is a bit unintuitive and makes to code harder to maintain.\r\n\r\nI would propose changing the schema to have the following queries:\r\n`viewer: User` - returns currently authenticated user\r\n`user(id: ID!): User` - resolves a user by ID, where ID is required\n", "before_files": [{"content": "import graphene\nimport graphene_django_optimizer as gql_optimizer\nfrom django.db.models import Q\nfrom i18naddress import get_validation_rules\n\nfrom ...account import models\nfrom ...core.utils import get_client_ip, get_country_by_ip\nfrom ..utils import filter_by_query_param\nfrom .types import AddressValidationData, ChoiceValue, User\n\nUSER_SEARCH_FIELDS = (\n    'email', 'default_shipping_address__first_name',\n    'default_shipping_address__last_name', 'default_shipping_address__city',\n    'default_shipping_address__country')\n\n\ndef resolve_user(info, id):\n    logged_user = info.context.user\n    if not id:\n        return logged_user\n    user = graphene.Node.get_node_from_global_id(info, id, User)\n    if logged_user.has_perm('account.manage_users') or user == logged_user:\n        return user\n    return None\n\n\ndef resolve_customers(info, query):\n    qs = models.User.objects.filter(\n        Q(is_staff=False) | (Q(is_staff=True) & Q(orders__isnull=False)))\n    qs = filter_by_query_param(\n        queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)\n    qs = qs.order_by('email')\n    qs = qs.distinct()\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_staff_users(info, query):\n    qs = models.User.objects.filter(is_staff=True)\n    qs = filter_by_query_param(\n        queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)\n    qs = qs.order_by('email')\n    qs = qs.distinct()\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_address_validator(info, input):\n    country_code = input['country_code']\n    if not country_code:\n        client_ip = get_client_ip(info.context)\n        country = get_country_by_ip(client_ip)\n        if country:\n            country_code = country.code\n        else:\n            return None\n    params = {\n        'country_code': country_code,\n        'country_area': input['country_area'],\n        'city_area': input['city_area']}\n    rules = get_validation_rules(params)\n    return AddressValidationData(\n        country_code=rules.country_code,\n        country_name=rules.country_name,\n        address_format=rules.address_format,\n        address_latin_format=rules.address_latin_format,\n        allowed_fields=rules.allowed_fields,\n        required_fields=rules.required_fields,\n        upper_fields=rules.upper_fields,\n        country_area_type=rules.country_area_type,\n        country_area_choices=[\n            ChoiceValue(area[0], area[1])\n            for area in rules.country_area_choices],\n        city_type=rules.city_type,\n        city_area_choices=[\n            ChoiceValue(area[0], area[1]) for area in rules.city_area_choices],\n        postal_code_type=rules.postal_code_type,\n        postal_code_matchers=[\n            compiled.pattern for compiled in rules.postal_code_matchers],\n        postal_code_examples=rules.postal_code_examples,\n        postal_code_prefix=rules.postal_code_prefix)\n", "path": "saleor/graphql/account/resolvers.py"}, {"content": "import graphene\nimport graphene_django_optimizer as gql_optimizer\nfrom django.contrib.auth import get_user_model\nfrom graphene import relay\n\nfrom ...account import models\nfrom ...core.permissions import get_permissions\nfrom ..core.types.common import (\n    CountableDjangoObjectType, CountryDisplay, PermissionDisplay)\nfrom ..utils import format_permissions_for_display\n\n\nclass AddressInput(graphene.InputObjectType):\n    first_name = graphene.String(description='Given name.')\n    last_name = graphene.String(description='Family name.')\n    company_name = graphene.String(description='Company or organization.')\n    street_address_1 = graphene.String(description='Address.')\n    street_address_2 = graphene.String(description='Address.')\n    city = graphene.String(description='City.')\n    city_area = graphene.String(description='District.')\n    postal_code = graphene.String(description='Postal code.')\n    country = graphene.String(required=True, description='Country.')\n    country_area = graphene.String(description='State or province.')\n    phone = graphene.String(description='Phone number.')\n\n\nclass Address(CountableDjangoObjectType):\n    country = graphene.Field(\n        CountryDisplay, required=True, description='Default shop\\'s country')\n\n    class Meta:\n        exclude_fields = ['user_set', 'user_addresses']\n        description = 'Represents user address data.'\n        interfaces = [relay.Node]\n        model = models.Address\n\n    def resolve_country(self, info):\n        return CountryDisplay(\n            code=self.country.code, country=self.country.name)\n\n\nclass User(CountableDjangoObjectType):\n    permissions = graphene.List(\n        PermissionDisplay, description='List of user\\'s permissions.')\n    addresses = gql_optimizer.field(\n        graphene.List(\n            Address, description='List of all user\\'s addresses.'),\n        model_field='addresses')\n\n    class Meta:\n        exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']\n        description = 'Represents user data.'\n        interfaces = [relay.Node]\n        model = get_user_model()\n\n    def resolve_permissions(self, info, **kwargs):\n        if self.is_superuser:\n            permissions = get_permissions()\n        else:\n            permissions = self.user_permissions.prefetch_related(\n                'content_type').order_by('codename')\n        return format_permissions_for_display(permissions)\n\n    def resolve_addresses(self, info, **kwargs):\n        return self.addresses.all()\n\n\nclass AddressValidationInput(graphene.InputObjectType):\n    country_code = graphene.String()\n    country_area = graphene.String()\n    city_area = graphene.String()\n\n\nclass ChoiceValue(graphene.ObjectType):\n    raw = graphene.String()\n    verbose = graphene.String()\n\n\nclass AddressValidationData(graphene.ObjectType):\n    country_code = graphene.String()\n    country_name = graphene.String()\n    address_format = graphene.String()\n    address_latin_format = graphene.String()\n    allowed_fields = graphene.List(graphene.String)\n    required_fields = graphene.List(graphene.String)\n    upper_fields = graphene.List(graphene.String)\n    country_area_type = graphene.String()\n    country_area_choices = graphene.List(ChoiceValue)\n    city_type = graphene.String()\n    city_area_choices = graphene.List(ChoiceValue)\n    postal_code_type = graphene.String()\n    postal_code_matchers = graphene.List(graphene.String)\n    postal_code_examples = graphene.List(graphene.String)\n    postal_code_prefix = graphene.String()\n", "path": "saleor/graphql/account/types.py"}, {"content": "import graphene\nfrom graphql_jwt.decorators import login_required, permission_required\n\nfrom ..core.fields import PrefetchingConnectionField\nfrom ..descriptions import DESCRIPTIONS\nfrom .mutations import (\n    AddressCreate, AddressDelete, AddressUpdate, CustomerCreate,\n    CustomerDelete, CustomerPasswordReset, CustomerRegister, CustomerUpdate,\n    LoggedUserUpdate, PasswordReset, SetPassword, StaffCreate, StaffDelete,\n    StaffUpdate)\nfrom .resolvers import (\n    resolve_address_validator, resolve_customers, resolve_staff_users,\n    resolve_user)\nfrom .types import AddressValidationData, AddressValidationInput, User\n\n\nclass AccountQueries(graphene.ObjectType):\n    address_validator = graphene.Field(\n        AddressValidationData,\n        input=graphene.Argument(AddressValidationInput, required=True))\n    customers = PrefetchingConnectionField(\n        User, description='List of the shop\\'s customers.',\n        query=graphene.String(description=DESCRIPTIONS['user']))\n    staff_users = PrefetchingConnectionField(\n        User, description='List of the shop\\'s staff users.',\n        query=graphene.String(description=DESCRIPTIONS['user']))\n    user = graphene.Field(\n        User, id=graphene.Argument(graphene.ID, required=True),\n        description='Lookup an user by ID.')\n\n    def resolve_address_validator(self, info, input):\n        return resolve_address_validator(info, input)\n\n    @permission_required('account.manage_users')\n    def resolve_customers(self, info, query=None, **kwargs):\n        return resolve_customers(info, query=query)\n\n    @permission_required('account.manage_staff')\n    def resolve_staff_users(self, info, query=None, **kwargs):\n        return resolve_staff_users(info, query=query)\n\n    @login_required\n    def resolve_user(self, info, id):\n        return resolve_user(info, id)\n\n\nclass AccountMutations(graphene.ObjectType):\n    password_reset = PasswordReset.Field()\n    set_password = SetPassword.Field()\n\n    customer_create = CustomerCreate.Field()\n    customer_delete = CustomerDelete.Field()\n    customer_password_reset = CustomerPasswordReset.Field()\n    customer_register = CustomerRegister.Field()\n    customer_update = CustomerUpdate.Field()\n\n    logged_user_update = LoggedUserUpdate.Field()\n\n    staff_create = StaffCreate.Field()\n    staff_delete = StaffDelete.Field()\n    staff_update = StaffUpdate.Field()\n\n    address_create = AddressCreate.Field()\n    address_delete = AddressDelete.Field()\n    address_update = AddressUpdate.Field()\n", "path": "saleor/graphql/account/schema.py"}], "after_files": [{"content": "import graphene_django_optimizer as gql_optimizer\nfrom django.db.models import Q\nfrom i18naddress import get_validation_rules\n\nfrom ...account import models\nfrom ...core.utils import get_client_ip, get_country_by_ip\nfrom ..utils import filter_by_query_param\nfrom .types import AddressValidationData, ChoiceValue\n\nUSER_SEARCH_FIELDS = (\n    'email', 'default_shipping_address__first_name',\n    'default_shipping_address__last_name', 'default_shipping_address__city',\n    'default_shipping_address__country')\n\n\ndef resolve_customers(info, query):\n    qs = models.User.objects.filter(\n        Q(is_staff=False) | (Q(is_staff=True) & Q(orders__isnull=False)))\n    qs = filter_by_query_param(\n        queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)\n    qs = qs.order_by('email')\n    qs = qs.distinct()\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_staff_users(info, query):\n    qs = models.User.objects.filter(is_staff=True)\n    qs = filter_by_query_param(\n        queryset=qs, query=query, search_fields=USER_SEARCH_FIELDS)\n    qs = qs.order_by('email')\n    qs = qs.distinct()\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_address_validator(info, input):\n    country_code = input['country_code']\n    if not country_code:\n        client_ip = get_client_ip(info.context)\n        country = get_country_by_ip(client_ip)\n        if country:\n            country_code = country.code\n        else:\n            return None\n    params = {\n        'country_code': country_code,\n        'country_area': input['country_area'],\n        'city_area': input['city_area']}\n    rules = get_validation_rules(params)\n    return AddressValidationData(\n        country_code=rules.country_code,\n        country_name=rules.country_name,\n        address_format=rules.address_format,\n        address_latin_format=rules.address_latin_format,\n        allowed_fields=rules.allowed_fields,\n        required_fields=rules.required_fields,\n        upper_fields=rules.upper_fields,\n        country_area_type=rules.country_area_type,\n        country_area_choices=[\n            ChoiceValue(area[0], area[1])\n            for area in rules.country_area_choices],\n        city_type=rules.city_type,\n        city_area_choices=[\n            ChoiceValue(area[0], area[1]) for area in rules.city_area_choices],\n        postal_code_type=rules.postal_code_type,\n        postal_code_matchers=[\n            compiled.pattern for compiled in rules.postal_code_matchers],\n        postal_code_examples=rules.postal_code_examples,\n        postal_code_prefix=rules.postal_code_prefix)\n", "path": "saleor/graphql/account/resolvers.py"}, {"content": "import graphene\nimport graphene_django_optimizer as gql_optimizer\nfrom django.contrib.auth import get_user_model\nfrom graphene import relay\nfrom graphql_jwt.decorators import permission_required\n\nfrom ...account import models\nfrom ...core.permissions import get_permissions\nfrom ..core.fields import PrefetchingConnectionField\nfrom ..core.types.common import (\n    CountableDjangoObjectType, CountryDisplay, PermissionDisplay)\nfrom ..utils import format_permissions_for_display\n\n\nclass AddressInput(graphene.InputObjectType):\n    first_name = graphene.String(description='Given name.')\n    last_name = graphene.String(description='Family name.')\n    company_name = graphene.String(description='Company or organization.')\n    street_address_1 = graphene.String(description='Address.')\n    street_address_2 = graphene.String(description='Address.')\n    city = graphene.String(description='City.')\n    city_area = graphene.String(description='District.')\n    postal_code = graphene.String(description='Postal code.')\n    country = graphene.String(required=True, description='Country.')\n    country_area = graphene.String(description='State or province.')\n    phone = graphene.String(description='Phone number.')\n\n\nclass Address(CountableDjangoObjectType):\n    country = graphene.Field(\n        CountryDisplay, required=True, description='Default shop\\'s country')\n\n    class Meta:\n        exclude_fields = ['user_set', 'user_addresses']\n        description = 'Represents user address data.'\n        interfaces = [relay.Node]\n        model = models.Address\n\n    def resolve_country(self, info):\n        return CountryDisplay(\n            code=self.country.code, country=self.country.name)\n\n\nclass User(CountableDjangoObjectType):\n    permissions = graphene.List(\n        PermissionDisplay, description='List of user\\'s permissions.')\n    addresses = gql_optimizer.field(\n        PrefetchingConnectionField(\n            Address, description='List of all user\\'s addresses.'),\n        model_field='addresses')\n    note = graphene.String(description='A note about the customer')\n\n    class Meta:\n        exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']\n        description = 'Represents user data.'\n        interfaces = [relay.Node]\n        model = get_user_model()\n\n    def resolve_permissions(self, info, **kwargs):\n        if self.is_superuser:\n            permissions = get_permissions()\n        else:\n            permissions = self.user_permissions.prefetch_related(\n                'content_type').order_by('codename')\n        return format_permissions_for_display(permissions)\n\n    def resolve_addresses(self, info, **kwargs):\n        return self.addresses.all()\n\n    @permission_required('account.manage_users')\n    def resolve_note(self, info):\n        return self.note\n\n\nclass AddressValidationInput(graphene.InputObjectType):\n    country_code = graphene.String()\n    country_area = graphene.String()\n    city_area = graphene.String()\n\n\nclass ChoiceValue(graphene.ObjectType):\n    raw = graphene.String()\n    verbose = graphene.String()\n\n\nclass AddressValidationData(graphene.ObjectType):\n    country_code = graphene.String()\n    country_name = graphene.String()\n    address_format = graphene.String()\n    address_latin_format = graphene.String()\n    allowed_fields = graphene.List(graphene.String)\n    required_fields = graphene.List(graphene.String)\n    upper_fields = graphene.List(graphene.String)\n    country_area_type = graphene.String()\n    country_area_choices = graphene.List(ChoiceValue)\n    city_type = graphene.String()\n    city_area_choices = graphene.List(ChoiceValue)\n    postal_code_type = graphene.String()\n    postal_code_matchers = graphene.List(graphene.String)\n    postal_code_examples = graphene.List(graphene.String)\n    postal_code_prefix = graphene.String()\n", "path": "saleor/graphql/account/types.py"}, {"content": "import graphene\nfrom graphql_jwt.decorators import login_required, permission_required\n\nfrom ..core.fields import PrefetchingConnectionField\nfrom ..descriptions import DESCRIPTIONS\nfrom .mutations import (\n    AddressCreate, AddressDelete, AddressUpdate, CustomerCreate,\n    CustomerDelete, CustomerPasswordReset, CustomerRegister, CustomerUpdate,\n    LoggedUserUpdate, PasswordReset, SetPassword, StaffCreate, StaffDelete,\n    StaffUpdate)\nfrom .resolvers import (\n    resolve_address_validator, resolve_customers, resolve_staff_users)\nfrom .types import AddressValidationData, AddressValidationInput, User\n\n\nclass AccountQueries(graphene.ObjectType):\n    address_validator = graphene.Field(\n        AddressValidationData,\n        input=graphene.Argument(AddressValidationInput, required=True))\n    customers = PrefetchingConnectionField(\n        User, description='List of the shop\\'s customers.',\n        query=graphene.String(description=DESCRIPTIONS['user']))\n    me = graphene.Field(\n        User, description='Logged in user data.')\n    staff_users = PrefetchingConnectionField(\n        User, description='List of the shop\\'s staff users.',\n        query=graphene.String(description=DESCRIPTIONS['user']))\n    user = graphene.Field(\n        User, id=graphene.Argument(graphene.ID, required=True),\n        description='Lookup an user by ID.')\n\n    def resolve_address_validator(self, info, input):\n        return resolve_address_validator(info, input)\n\n    @permission_required('account.manage_users')\n    def resolve_customers(self, info, query=None, **kwargs):\n        return resolve_customers(info, query=query)\n\n    @login_required\n    def resolve_me(self, info):\n        return info.context.user\n\n    @permission_required('account.manage_staff')\n    def resolve_staff_users(self, info, query=None, **kwargs):\n        return resolve_staff_users(info, query=query)\n\n    @permission_required('account.manage_users')\n    def resolve_user(self, info, id):\n        return graphene.Node.get_node_from_global_id(info, id, User)\n\n\nclass AccountMutations(graphene.ObjectType):\n    password_reset = PasswordReset.Field()\n    set_password = SetPassword.Field()\n\n    customer_create = CustomerCreate.Field()\n    customer_delete = CustomerDelete.Field()\n    customer_password_reset = CustomerPasswordReset.Field()\n    customer_register = CustomerRegister.Field()\n    customer_update = CustomerUpdate.Field()\n\n    logged_user_update = LoggedUserUpdate.Field()\n\n    staff_create = StaffCreate.Field()\n    staff_delete = StaffDelete.Field()\n    staff_update = StaffUpdate.Field()\n\n    address_create = AddressCreate.Field()\n    address_delete = AddressDelete.Field()\n    address_update = AddressUpdate.Field()\n", "path": "saleor/graphql/account/schema.py"}]}