We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Query order as service account 
I'm not able to query order by id as a service account. 
`resolve_order` have `login_required` this decorator doesn't allow to run the function as a service account. 

--- 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/order/resolvers.py`
Content:
```
1 import graphene
2 import graphene_django_optimizer as gql_optimizer
3 
4 from ...core.permissions import OrderPermissions
5 from ...order import OrderStatus, models
6 from ...order.events import OrderEvents
7 from ...order.models import OrderEvent
8 from ...order.utils import sum_order_totals
9 from ..utils import filter_by_period, filter_by_query_param, sort_queryset
10 from .enums import OrderStatusFilter
11 from .sorters import OrderSortField
12 from .types import Order
13 
14 ORDER_SEARCH_FIELDS = ("id", "discount_name", "token", "user_email", "user__email")
15 
16 
17 def filter_orders(qs, info, created, status, query):
18     qs = filter_by_query_param(qs, query, ORDER_SEARCH_FIELDS)
19 
20     # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.
21     # filter orders by status
22     if status is not None:
23         if status == OrderStatusFilter.READY_TO_FULFILL:
24             qs = qs.ready_to_fulfill()
25         elif status == OrderStatusFilter.READY_TO_CAPTURE:
26             qs = qs.ready_to_capture()
27 
28     # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.
29     # filter orders by creation date
30     if created is not None:
31         qs = filter_by_period(qs, created, "created")
32 
33     return gql_optimizer.query(qs, info)
34 
35 
36 def resolve_orders(info, created, status, query, sort_by=None):
37     qs = models.Order.objects.confirmed()
38     qs = sort_queryset(qs, sort_by, OrderSortField)
39     return filter_orders(qs, info, created, status, query)
40 
41 
42 def resolve_draft_orders(info, created, query, sort_by=None):
43     qs = models.Order.objects.drafts()
44     qs = sort_queryset(qs, sort_by, OrderSortField)
45     return filter_orders(qs, info, created, None, query)
46 
47 
48 def resolve_orders_total(_info, period):
49     qs = models.Order.objects.confirmed().exclude(status=OrderStatus.CANCELED)
50     qs = filter_by_period(qs, period, "created")
51     return sum_order_totals(qs)
52 
53 
54 def resolve_order(info, order_id):
55     """Return order only for user assigned to it or proper staff user."""
56     user = info.context.user
57     order = graphene.Node.get_node_from_global_id(info, order_id, Order)
58     if user.has_perm(OrderPermissions.MANAGE_ORDERS) or order.user == user:
59         return order
60     return None
61 
62 
63 def resolve_homepage_events():
64     # Filter only selected events to be displayed on homepage.
65     types = [
66         OrderEvents.PLACED,
67         OrderEvents.PLACED_FROM_DRAFT,
68         OrderEvents.ORDER_FULLY_PAID,
69     ]
70     return OrderEvent.objects.filter(type__in=types)
71 
72 
73 def resolve_order_by_token(token):
74     return models.Order.objects.filter(token=token).first()
75
```

Path: `saleor/graphql/order/schema.py`
Content:
```
1 import graphene
2 from graphql_jwt.decorators import login_required
3 
4 from ...core.permissions import OrderPermissions
5 from ..core.enums import ReportingPeriod
6 from ..core.fields import FilterInputConnectionField, PrefetchingConnectionField
7 from ..core.types import FilterInputObjectType, TaxedMoney
8 from ..decorators import permission_required
9 from .bulk_mutations.draft_orders import DraftOrderBulkDelete, DraftOrderLinesBulkDelete
10 from .bulk_mutations.orders import OrderBulkCancel
11 from .enums import OrderStatusFilter
12 from .filters import DraftOrderFilter, OrderFilter
13 from .mutations.draft_orders import (
14     DraftOrderComplete,
15     DraftOrderCreate,
16     DraftOrderDelete,
17     DraftOrderLineDelete,
18     DraftOrderLinesCreate,
19     DraftOrderLineUpdate,
20     DraftOrderUpdate,
21 )
22 from .mutations.fulfillments import (
23     FulfillmentCancel,
24     FulfillmentClearMeta,
25     FulfillmentClearPrivateMeta,
26     FulfillmentCreate,
27     FulfillmentUpdateMeta,
28     FulfillmentUpdatePrivateMeta,
29     FulfillmentUpdateTracking,
30 )
31 from .mutations.orders import (
32     OrderAddNote,
33     OrderCancel,
34     OrderCapture,
35     OrderClearMeta,
36     OrderClearPrivateMeta,
37     OrderMarkAsPaid,
38     OrderRefund,
39     OrderUpdate,
40     OrderUpdateMeta,
41     OrderUpdatePrivateMeta,
42     OrderUpdateShipping,
43     OrderVoid,
44 )
45 from .resolvers import (
46     resolve_draft_orders,
47     resolve_homepage_events,
48     resolve_order,
49     resolve_order_by_token,
50     resolve_orders,
51     resolve_orders_total,
52 )
53 from .sorters import OrderSortingInput
54 from .types import Order, OrderEvent
55 
56 
57 class OrderFilterInput(FilterInputObjectType):
58     class Meta:
59         filterset_class = OrderFilter
60 
61 
62 class OrderDraftFilterInput(FilterInputObjectType):
63     class Meta:
64         filterset_class = DraftOrderFilter
65 
66 
67 class OrderQueries(graphene.ObjectType):
68     homepage_events = PrefetchingConnectionField(
69         OrderEvent,
70         description=(
71             "List of activity events to display on "
72             "homepage (at the moment it only contains order-events)."
73         ),
74     )
75     order = graphene.Field(
76         Order,
77         description="Look up an order by ID.",
78         id=graphene.Argument(graphene.ID, description="ID of an order.", required=True),
79     )
80     orders = FilterInputConnectionField(
81         Order,
82         sort_by=OrderSortingInput(description="Sort orders."),
83         filter=OrderFilterInput(description="Filtering options for orders."),
84         created=graphene.Argument(
85             ReportingPeriod,
86             description=(
87                 "Filter orders from a selected timespan. "
88                 "DEPRECATED: Will be removed in Saleor 2.11, "
89                 "use the `filter` field instead."
90             ),
91         ),
92         status=graphene.Argument(
93             OrderStatusFilter,
94             description=(
95                 "Filter order by status. "
96                 "DEPRECATED: Will be removed in Saleor 2.11, "
97                 "use the `filter` field instead."
98             ),
99         ),
100         description="List of orders.",
101     )
102     draft_orders = FilterInputConnectionField(
103         Order,
104         sort_by=OrderSortingInput(description="Sort draft orders."),
105         filter=OrderDraftFilterInput(description="Filtering options for draft orders."),
106         created=graphene.Argument(
107             ReportingPeriod,
108             description=(
109                 "Filter draft orders from a selected timespan. "
110                 "DEPRECATED: Will be removed in Saleor 2.11, "
111                 "use the `filter` field instead."
112             ),
113         ),
114         description="List of draft orders.",
115     )
116     orders_total = graphene.Field(
117         TaxedMoney,
118         description="Return the total sales amount from a specific period.",
119         period=graphene.Argument(ReportingPeriod, description="A period of time."),
120     )
121     order_by_token = graphene.Field(
122         Order,
123         description="Look up an order by token.",
124         token=graphene.Argument(
125             graphene.UUID, description="The order's token.", required=True
126         ),
127     )
128 
129     @permission_required(OrderPermissions.MANAGE_ORDERS)
130     def resolve_homepage_events(self, *_args, **_kwargs):
131         return resolve_homepage_events()
132 
133     @login_required
134     def resolve_order(self, info, **data):
135         return resolve_order(info, data.get("id"))
136 
137     @permission_required(OrderPermissions.MANAGE_ORDERS)
138     def resolve_orders(
139         self, info, created=None, status=None, query=None, sort_by=None, **_kwargs
140     ):
141         return resolve_orders(info, created, status, query, sort_by)
142 
143     @permission_required(OrderPermissions.MANAGE_ORDERS)
144     def resolve_draft_orders(
145         self, info, created=None, query=None, sort_by=None, **_kwargs
146     ):
147         return resolve_draft_orders(info, created, query, sort_by)
148 
149     @permission_required(OrderPermissions.MANAGE_ORDERS)
150     def resolve_orders_total(self, info, period, **_kwargs):
151         return resolve_orders_total(info, period)
152 
153     def resolve_order_by_token(self, _info, token):
154         return resolve_order_by_token(token)
155 
156 
157 class OrderMutations(graphene.ObjectType):
158     draft_order_complete = DraftOrderComplete.Field()
159     draft_order_create = DraftOrderCreate.Field()
160     draft_order_delete = DraftOrderDelete.Field()
161     draft_order_bulk_delete = DraftOrderBulkDelete.Field()
162     draft_order_lines_bulk_delete = DraftOrderLinesBulkDelete.Field()
163     draft_order_lines_create = DraftOrderLinesCreate.Field()
164     draft_order_line_delete = DraftOrderLineDelete.Field()
165     draft_order_line_update = DraftOrderLineUpdate.Field()
166     draft_order_update = DraftOrderUpdate.Field()
167 
168     order_add_note = OrderAddNote.Field()
169     order_cancel = OrderCancel.Field()
170     order_capture = OrderCapture.Field()
171     order_clear_private_meta = OrderClearPrivateMeta.Field()
172     order_clear_meta = OrderClearMeta.Field()
173     order_fulfillment_cancel = FulfillmentCancel.Field()
174     order_fulfillment_create = FulfillmentCreate.Field()
175     order_fulfillment_update_tracking = FulfillmentUpdateTracking.Field()
176     order_fulfillment_clear_meta = FulfillmentClearMeta.Field()
177     order_fulfillment_clear_private_meta = FulfillmentClearPrivateMeta.Field()
178     order_fulfillment_update_meta = FulfillmentUpdateMeta.Field()
179     order_fulfillment_update_private_meta = FulfillmentUpdatePrivateMeta.Field()
180     order_mark_as_paid = OrderMarkAsPaid.Field()
181     order_refund = OrderRefund.Field()
182     order_update = OrderUpdate.Field()
183     order_update_meta = OrderUpdateMeta.Field()
184     order_update_private_meta = OrderUpdatePrivateMeta.Field()
185     order_update_shipping = OrderUpdateShipping.Field()
186     order_void = OrderVoid.Field()
187 
188     order_bulk_cancel = OrderBulkCancel.Field()
189
```
--- 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/order/resolvers.py b/saleor/graphql/order/resolvers.py
--- a/saleor/graphql/order/resolvers.py
+++ b/saleor/graphql/order/resolvers.py
@@ -1,7 +1,6 @@
 import graphene
 import graphene_django_optimizer as gql_optimizer
 
-from ...core.permissions import OrderPermissions
 from ...order import OrderStatus, models
 from ...order.events import OrderEvents
 from ...order.models import OrderEvent
@@ -52,12 +51,7 @@
 
 
 def resolve_order(info, order_id):
-    """Return order only for user assigned to it or proper staff user."""
-    user = info.context.user
-    order = graphene.Node.get_node_from_global_id(info, order_id, Order)
-    if user.has_perm(OrderPermissions.MANAGE_ORDERS) or order.user == user:
-        return order
-    return None
+    return graphene.Node.get_node_from_global_id(info, order_id, Order)
 
 
 def resolve_homepage_events():
diff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.py
--- a/saleor/graphql/order/schema.py
+++ b/saleor/graphql/order/schema.py
@@ -1,5 +1,4 @@
 import graphene
-from graphql_jwt.decorators import login_required
 
 from ...core.permissions import OrderPermissions
 from ..core.enums import ReportingPeriod
@@ -130,7 +129,7 @@
     def resolve_homepage_events(self, *_args, **_kwargs):
         return resolve_homepage_events()
 
-    @login_required
+    @permission_required(OrderPermissions.MANAGE_ORDERS)
     def resolve_order(self, info, **data):
         return resolve_order(info, data.get("id"))

{"golden_diff": "diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.py\n--- a/saleor/graphql/order/resolvers.py\n+++ b/saleor/graphql/order/resolvers.py\n@@ -1,7 +1,6 @@\n import graphene\n import graphene_django_optimizer as gql_optimizer\n \n-from ...core.permissions import OrderPermissions\n from ...order import OrderStatus, models\n from ...order.events import OrderEvents\n from ...order.models import OrderEvent\n@@ -52,12 +51,7 @@\n \n \n def resolve_order(info, order_id):\n-    \"\"\"Return order only for user assigned to it or proper staff user.\"\"\"\n-    user = info.context.user\n-    order = graphene.Node.get_node_from_global_id(info, order_id, Order)\n-    if user.has_perm(OrderPermissions.MANAGE_ORDERS) or order.user == user:\n-        return order\n-    return None\n+    return graphene.Node.get_node_from_global_id(info, order_id, Order)\n \n \n def resolve_homepage_events():\ndiff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.py\n--- a/saleor/graphql/order/schema.py\n+++ b/saleor/graphql/order/schema.py\n@@ -1,5 +1,4 @@\n import graphene\n-from graphql_jwt.decorators import login_required\n \n from ...core.permissions import OrderPermissions\n from ..core.enums import ReportingPeriod\n@@ -130,7 +129,7 @@\n     def resolve_homepage_events(self, *_args, **_kwargs):\n         return resolve_homepage_events()\n \n-    @login_required\n+    @permission_required(OrderPermissions.MANAGE_ORDERS)\n     def resolve_order(self, info, **data):\n         return resolve_order(info, data.get(\"id\"))\n", "issue": "Query order as service account \nI'm not able to query order by id as a service account. \r\n`resolve_order` have `login_required` this decorator doesn't allow to run the function as a service account. \n", "before_files": [{"content": "import graphene\nimport graphene_django_optimizer as gql_optimizer\n\nfrom ...core.permissions import OrderPermissions\nfrom ...order import OrderStatus, models\nfrom ...order.events import OrderEvents\nfrom ...order.models import OrderEvent\nfrom ...order.utils import sum_order_totals\nfrom ..utils import filter_by_period, filter_by_query_param, sort_queryset\nfrom .enums import OrderStatusFilter\nfrom .sorters import OrderSortField\nfrom .types import Order\n\nORDER_SEARCH_FIELDS = (\"id\", \"discount_name\", \"token\", \"user_email\", \"user__email\")\n\n\ndef filter_orders(qs, info, created, status, query):\n    qs = filter_by_query_param(qs, query, ORDER_SEARCH_FIELDS)\n\n    # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.\n    # filter orders by status\n    if status is not None:\n        if status == OrderStatusFilter.READY_TO_FULFILL:\n            qs = qs.ready_to_fulfill()\n        elif status == OrderStatusFilter.READY_TO_CAPTURE:\n            qs = qs.ready_to_capture()\n\n    # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.\n    # filter orders by creation date\n    if created is not None:\n        qs = filter_by_period(qs, created, \"created\")\n\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_orders(info, created, status, query, sort_by=None):\n    qs = models.Order.objects.confirmed()\n    qs = sort_queryset(qs, sort_by, OrderSortField)\n    return filter_orders(qs, info, created, status, query)\n\n\ndef resolve_draft_orders(info, created, query, sort_by=None):\n    qs = models.Order.objects.drafts()\n    qs = sort_queryset(qs, sort_by, OrderSortField)\n    return filter_orders(qs, info, created, None, query)\n\n\ndef resolve_orders_total(_info, period):\n    qs = models.Order.objects.confirmed().exclude(status=OrderStatus.CANCELED)\n    qs = filter_by_period(qs, period, \"created\")\n    return sum_order_totals(qs)\n\n\ndef resolve_order(info, order_id):\n    \"\"\"Return order only for user assigned to it or proper staff user.\"\"\"\n    user = info.context.user\n    order = graphene.Node.get_node_from_global_id(info, order_id, Order)\n    if user.has_perm(OrderPermissions.MANAGE_ORDERS) or order.user == user:\n        return order\n    return None\n\n\ndef resolve_homepage_events():\n    # Filter only selected events to be displayed on homepage.\n    types = [\n        OrderEvents.PLACED,\n        OrderEvents.PLACED_FROM_DRAFT,\n        OrderEvents.ORDER_FULLY_PAID,\n    ]\n    return OrderEvent.objects.filter(type__in=types)\n\n\ndef resolve_order_by_token(token):\n    return models.Order.objects.filter(token=token).first()\n", "path": "saleor/graphql/order/resolvers.py"}, {"content": "import graphene\nfrom graphql_jwt.decorators import login_required\n\nfrom ...core.permissions import OrderPermissions\nfrom ..core.enums import ReportingPeriod\nfrom ..core.fields import FilterInputConnectionField, PrefetchingConnectionField\nfrom ..core.types import FilterInputObjectType, TaxedMoney\nfrom ..decorators import permission_required\nfrom .bulk_mutations.draft_orders import DraftOrderBulkDelete, DraftOrderLinesBulkDelete\nfrom .bulk_mutations.orders import OrderBulkCancel\nfrom .enums import OrderStatusFilter\nfrom .filters import DraftOrderFilter, OrderFilter\nfrom .mutations.draft_orders import (\n    DraftOrderComplete,\n    DraftOrderCreate,\n    DraftOrderDelete,\n    DraftOrderLineDelete,\n    DraftOrderLinesCreate,\n    DraftOrderLineUpdate,\n    DraftOrderUpdate,\n)\nfrom .mutations.fulfillments import (\n    FulfillmentCancel,\n    FulfillmentClearMeta,\n    FulfillmentClearPrivateMeta,\n    FulfillmentCreate,\n    FulfillmentUpdateMeta,\n    FulfillmentUpdatePrivateMeta,\n    FulfillmentUpdateTracking,\n)\nfrom .mutations.orders import (\n    OrderAddNote,\n    OrderCancel,\n    OrderCapture,\n    OrderClearMeta,\n    OrderClearPrivateMeta,\n    OrderMarkAsPaid,\n    OrderRefund,\n    OrderUpdate,\n    OrderUpdateMeta,\n    OrderUpdatePrivateMeta,\n    OrderUpdateShipping,\n    OrderVoid,\n)\nfrom .resolvers import (\n    resolve_draft_orders,\n    resolve_homepage_events,\n    resolve_order,\n    resolve_order_by_token,\n    resolve_orders,\n    resolve_orders_total,\n)\nfrom .sorters import OrderSortingInput\nfrom .types import Order, OrderEvent\n\n\nclass OrderFilterInput(FilterInputObjectType):\n    class Meta:\n        filterset_class = OrderFilter\n\n\nclass OrderDraftFilterInput(FilterInputObjectType):\n    class Meta:\n        filterset_class = DraftOrderFilter\n\n\nclass OrderQueries(graphene.ObjectType):\n    homepage_events = PrefetchingConnectionField(\n        OrderEvent,\n        description=(\n            \"List of activity events to display on \"\n            \"homepage (at the moment it only contains order-events).\"\n        ),\n    )\n    order = graphene.Field(\n        Order,\n        description=\"Look up an order by ID.\",\n        id=graphene.Argument(graphene.ID, description=\"ID of an order.\", required=True),\n    )\n    orders = FilterInputConnectionField(\n        Order,\n        sort_by=OrderSortingInput(description=\"Sort orders.\"),\n        filter=OrderFilterInput(description=\"Filtering options for orders.\"),\n        created=graphene.Argument(\n            ReportingPeriod,\n            description=(\n                \"Filter orders from a selected timespan. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        status=graphene.Argument(\n            OrderStatusFilter,\n            description=(\n                \"Filter order by status. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        description=\"List of orders.\",\n    )\n    draft_orders = FilterInputConnectionField(\n        Order,\n        sort_by=OrderSortingInput(description=\"Sort draft orders.\"),\n        filter=OrderDraftFilterInput(description=\"Filtering options for draft orders.\"),\n        created=graphene.Argument(\n            ReportingPeriod,\n            description=(\n                \"Filter draft orders from a selected timespan. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        description=\"List of draft orders.\",\n    )\n    orders_total = graphene.Field(\n        TaxedMoney,\n        description=\"Return the total sales amount from a specific period.\",\n        period=graphene.Argument(ReportingPeriod, description=\"A period of time.\"),\n    )\n    order_by_token = graphene.Field(\n        Order,\n        description=\"Look up an order by token.\",\n        token=graphene.Argument(\n            graphene.UUID, description=\"The order's token.\", required=True\n        ),\n    )\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_homepage_events(self, *_args, **_kwargs):\n        return resolve_homepage_events()\n\n    @login_required\n    def resolve_order(self, info, **data):\n        return resolve_order(info, data.get(\"id\"))\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_orders(\n        self, info, created=None, status=None, query=None, sort_by=None, **_kwargs\n    ):\n        return resolve_orders(info, created, status, query, sort_by)\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_draft_orders(\n        self, info, created=None, query=None, sort_by=None, **_kwargs\n    ):\n        return resolve_draft_orders(info, created, query, sort_by)\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_orders_total(self, info, period, **_kwargs):\n        return resolve_orders_total(info, period)\n\n    def resolve_order_by_token(self, _info, token):\n        return resolve_order_by_token(token)\n\n\nclass OrderMutations(graphene.ObjectType):\n    draft_order_complete = DraftOrderComplete.Field()\n    draft_order_create = DraftOrderCreate.Field()\n    draft_order_delete = DraftOrderDelete.Field()\n    draft_order_bulk_delete = DraftOrderBulkDelete.Field()\n    draft_order_lines_bulk_delete = DraftOrderLinesBulkDelete.Field()\n    draft_order_lines_create = DraftOrderLinesCreate.Field()\n    draft_order_line_delete = DraftOrderLineDelete.Field()\n    draft_order_line_update = DraftOrderLineUpdate.Field()\n    draft_order_update = DraftOrderUpdate.Field()\n\n    order_add_note = OrderAddNote.Field()\n    order_cancel = OrderCancel.Field()\n    order_capture = OrderCapture.Field()\n    order_clear_private_meta = OrderClearPrivateMeta.Field()\n    order_clear_meta = OrderClearMeta.Field()\n    order_fulfillment_cancel = FulfillmentCancel.Field()\n    order_fulfillment_create = FulfillmentCreate.Field()\n    order_fulfillment_update_tracking = FulfillmentUpdateTracking.Field()\n    order_fulfillment_clear_meta = FulfillmentClearMeta.Field()\n    order_fulfillment_clear_private_meta = FulfillmentClearPrivateMeta.Field()\n    order_fulfillment_update_meta = FulfillmentUpdateMeta.Field()\n    order_fulfillment_update_private_meta = FulfillmentUpdatePrivateMeta.Field()\n    order_mark_as_paid = OrderMarkAsPaid.Field()\n    order_refund = OrderRefund.Field()\n    order_update = OrderUpdate.Field()\n    order_update_meta = OrderUpdateMeta.Field()\n    order_update_private_meta = OrderUpdatePrivateMeta.Field()\n    order_update_shipping = OrderUpdateShipping.Field()\n    order_void = OrderVoid.Field()\n\n    order_bulk_cancel = OrderBulkCancel.Field()\n", "path": "saleor/graphql/order/schema.py"}], "after_files": [{"content": "import graphene\nimport graphene_django_optimizer as gql_optimizer\n\nfrom ...order import OrderStatus, models\nfrom ...order.events import OrderEvents\nfrom ...order.models import OrderEvent\nfrom ...order.utils import sum_order_totals\nfrom ..utils import filter_by_period, filter_by_query_param, sort_queryset\nfrom .enums import OrderStatusFilter\nfrom .sorters import OrderSortField\nfrom .types import Order\n\nORDER_SEARCH_FIELDS = (\"id\", \"discount_name\", \"token\", \"user_email\", \"user__email\")\n\n\ndef filter_orders(qs, info, created, status, query):\n    qs = filter_by_query_param(qs, query, ORDER_SEARCH_FIELDS)\n\n    # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.\n    # filter orders by status\n    if status is not None:\n        if status == OrderStatusFilter.READY_TO_FULFILL:\n            qs = qs.ready_to_fulfill()\n        elif status == OrderStatusFilter.READY_TO_CAPTURE:\n            qs = qs.ready_to_capture()\n\n    # DEPRECATED: Will be removed in Saleor 2.11, use the `filter` field instead.\n    # filter orders by creation date\n    if created is not None:\n        qs = filter_by_period(qs, created, \"created\")\n\n    return gql_optimizer.query(qs, info)\n\n\ndef resolve_orders(info, created, status, query, sort_by=None):\n    qs = models.Order.objects.confirmed()\n    qs = sort_queryset(qs, sort_by, OrderSortField)\n    return filter_orders(qs, info, created, status, query)\n\n\ndef resolve_draft_orders(info, created, query, sort_by=None):\n    qs = models.Order.objects.drafts()\n    qs = sort_queryset(qs, sort_by, OrderSortField)\n    return filter_orders(qs, info, created, None, query)\n\n\ndef resolve_orders_total(_info, period):\n    qs = models.Order.objects.confirmed().exclude(status=OrderStatus.CANCELED)\n    qs = filter_by_period(qs, period, \"created\")\n    return sum_order_totals(qs)\n\n\ndef resolve_order(info, order_id):\n    return graphene.Node.get_node_from_global_id(info, order_id, Order)\n\n\ndef resolve_homepage_events():\n    # Filter only selected events to be displayed on homepage.\n    types = [\n        OrderEvents.PLACED,\n        OrderEvents.PLACED_FROM_DRAFT,\n        OrderEvents.ORDER_FULLY_PAID,\n    ]\n    return OrderEvent.objects.filter(type__in=types)\n\n\ndef resolve_order_by_token(token):\n    return models.Order.objects.filter(token=token).first()\n", "path": "saleor/graphql/order/resolvers.py"}, {"content": "import graphene\n\nfrom ...core.permissions import OrderPermissions\nfrom ..core.enums import ReportingPeriod\nfrom ..core.fields import FilterInputConnectionField, PrefetchingConnectionField\nfrom ..core.types import FilterInputObjectType, TaxedMoney\nfrom ..decorators import permission_required\nfrom .bulk_mutations.draft_orders import DraftOrderBulkDelete, DraftOrderLinesBulkDelete\nfrom .bulk_mutations.orders import OrderBulkCancel\nfrom .enums import OrderStatusFilter\nfrom .filters import DraftOrderFilter, OrderFilter\nfrom .mutations.draft_orders import (\n    DraftOrderComplete,\n    DraftOrderCreate,\n    DraftOrderDelete,\n    DraftOrderLineDelete,\n    DraftOrderLinesCreate,\n    DraftOrderLineUpdate,\n    DraftOrderUpdate,\n)\nfrom .mutations.fulfillments import (\n    FulfillmentCancel,\n    FulfillmentClearMeta,\n    FulfillmentClearPrivateMeta,\n    FulfillmentCreate,\n    FulfillmentUpdateMeta,\n    FulfillmentUpdatePrivateMeta,\n    FulfillmentUpdateTracking,\n)\nfrom .mutations.orders import (\n    OrderAddNote,\n    OrderCancel,\n    OrderCapture,\n    OrderClearMeta,\n    OrderClearPrivateMeta,\n    OrderMarkAsPaid,\n    OrderRefund,\n    OrderUpdate,\n    OrderUpdateMeta,\n    OrderUpdatePrivateMeta,\n    OrderUpdateShipping,\n    OrderVoid,\n)\nfrom .resolvers import (\n    resolve_draft_orders,\n    resolve_homepage_events,\n    resolve_order,\n    resolve_order_by_token,\n    resolve_orders,\n    resolve_orders_total,\n)\nfrom .sorters import OrderSortingInput\nfrom .types import Order, OrderEvent\n\n\nclass OrderFilterInput(FilterInputObjectType):\n    class Meta:\n        filterset_class = OrderFilter\n\n\nclass OrderDraftFilterInput(FilterInputObjectType):\n    class Meta:\n        filterset_class = DraftOrderFilter\n\n\nclass OrderQueries(graphene.ObjectType):\n    homepage_events = PrefetchingConnectionField(\n        OrderEvent,\n        description=(\n            \"List of activity events to display on \"\n            \"homepage (at the moment it only contains order-events).\"\n        ),\n    )\n    order = graphene.Field(\n        Order,\n        description=\"Look up an order by ID.\",\n        id=graphene.Argument(graphene.ID, description=\"ID of an order.\", required=True),\n    )\n    orders = FilterInputConnectionField(\n        Order,\n        sort_by=OrderSortingInput(description=\"Sort orders.\"),\n        filter=OrderFilterInput(description=\"Filtering options for orders.\"),\n        created=graphene.Argument(\n            ReportingPeriod,\n            description=(\n                \"Filter orders from a selected timespan. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        status=graphene.Argument(\n            OrderStatusFilter,\n            description=(\n                \"Filter order by status. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        description=\"List of orders.\",\n    )\n    draft_orders = FilterInputConnectionField(\n        Order,\n        sort_by=OrderSortingInput(description=\"Sort draft orders.\"),\n        filter=OrderDraftFilterInput(description=\"Filtering options for draft orders.\"),\n        created=graphene.Argument(\n            ReportingPeriod,\n            description=(\n                \"Filter draft orders from a selected timespan. \"\n                \"DEPRECATED: Will be removed in Saleor 2.11, \"\n                \"use the `filter` field instead.\"\n            ),\n        ),\n        description=\"List of draft orders.\",\n    )\n    orders_total = graphene.Field(\n        TaxedMoney,\n        description=\"Return the total sales amount from a specific period.\",\n        period=graphene.Argument(ReportingPeriod, description=\"A period of time.\"),\n    )\n    order_by_token = graphene.Field(\n        Order,\n        description=\"Look up an order by token.\",\n        token=graphene.Argument(\n            graphene.UUID, description=\"The order's token.\", required=True\n        ),\n    )\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_homepage_events(self, *_args, **_kwargs):\n        return resolve_homepage_events()\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_order(self, info, **data):\n        return resolve_order(info, data.get(\"id\"))\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_orders(\n        self, info, created=None, status=None, query=None, sort_by=None, **_kwargs\n    ):\n        return resolve_orders(info, created, status, query, sort_by)\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_draft_orders(\n        self, info, created=None, query=None, sort_by=None, **_kwargs\n    ):\n        return resolve_draft_orders(info, created, query, sort_by)\n\n    @permission_required(OrderPermissions.MANAGE_ORDERS)\n    def resolve_orders_total(self, info, period, **_kwargs):\n        return resolve_orders_total(info, period)\n\n    def resolve_order_by_token(self, _info, token):\n        return resolve_order_by_token(token)\n\n\nclass OrderMutations(graphene.ObjectType):\n    draft_order_complete = DraftOrderComplete.Field()\n    draft_order_create = DraftOrderCreate.Field()\n    draft_order_delete = DraftOrderDelete.Field()\n    draft_order_bulk_delete = DraftOrderBulkDelete.Field()\n    draft_order_lines_bulk_delete = DraftOrderLinesBulkDelete.Field()\n    draft_order_lines_create = DraftOrderLinesCreate.Field()\n    draft_order_line_delete = DraftOrderLineDelete.Field()\n    draft_order_line_update = DraftOrderLineUpdate.Field()\n    draft_order_update = DraftOrderUpdate.Field()\n\n    order_add_note = OrderAddNote.Field()\n    order_cancel = OrderCancel.Field()\n    order_capture = OrderCapture.Field()\n    order_clear_private_meta = OrderClearPrivateMeta.Field()\n    order_clear_meta = OrderClearMeta.Field()\n    order_fulfillment_cancel = FulfillmentCancel.Field()\n    order_fulfillment_create = FulfillmentCreate.Field()\n    order_fulfillment_update_tracking = FulfillmentUpdateTracking.Field()\n    order_fulfillment_clear_meta = FulfillmentClearMeta.Field()\n    order_fulfillment_clear_private_meta = FulfillmentClearPrivateMeta.Field()\n    order_fulfillment_update_meta = FulfillmentUpdateMeta.Field()\n    order_fulfillment_update_private_meta = FulfillmentUpdatePrivateMeta.Field()\n    order_mark_as_paid = OrderMarkAsPaid.Field()\n    order_refund = OrderRefund.Field()\n    order_update = OrderUpdate.Field()\n    order_update_meta = OrderUpdateMeta.Field()\n    order_update_private_meta = OrderUpdatePrivateMeta.Field()\n    order_update_shipping = OrderUpdateShipping.Field()\n    order_void = OrderVoid.Field()\n\n    order_bulk_cancel = OrderBulkCancel.Field()\n", "path": "saleor/graphql/order/schema.py"}]}