Skip to content

Commit 1b5e05c

Browse files
Adding AppSync events
1 parent 3d028e3 commit 1b5e05c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

aws_lambda_powertools/event_handler/events_appsync/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@
33
from abc import ABC, abstractmethod
44
from typing import Callable
55

6+
DEFAULT_ROUTE = "/default/*"
7+
68

79
class BaseRouter(ABC):
810
"""Abstract base class for Router (resolvers)"""
911

1012
@abstractmethod
1113
def on_publish(
1214
self,
13-
path: str = "/default/*",
15+
path: str = DEFAULT_ROUTE,
1416
aggregate: bool = True,
1517
) -> Callable:
1618
raise NotImplementedError
1719

1820
@abstractmethod
1921
def async_on_publish(
2022
self,
21-
path: str = "/default/*",
23+
path: str = DEFAULT_ROUTE,
2224
aggregate: bool = True,
2325
) -> Callable:
2426
raise NotImplementedError
2527

2628
@abstractmethod
2729
def on_subscribe(
2830
self,
29-
path: str = "/default/*",
31+
path: str = DEFAULT_ROUTE,
3032
) -> Callable:
3133
raise NotImplementedError
3234

aws_lambda_powertools/event_handler/events_appsync/functions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def is_valid_path(path: str) -> bool:
3535
>>> is_valid_path('users')
3636
False
3737
"""
38-
if path == "/*":
39-
return True
40-
return bool(PATH_REGEX.fullmatch(path))
38+
return True if path == "/*" else bool(PATH_REGEX.fullmatch(path))
4139

4240

4341
def find_best_route(routes: dict[str, Any], path: str):

aws_lambda_powertools/event_handler/events_appsync/router.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from aws_lambda_powertools.event_handler.events_appsync._registry import ResolverEventsRegistry
6-
from aws_lambda_powertools.event_handler.events_appsync.base import BaseRouter
6+
from aws_lambda_powertools.event_handler.events_appsync.base import DEFAULT_ROUTE, BaseRouter
77

88
if TYPE_CHECKING:
99
from collections.abc import Callable
@@ -71,7 +71,7 @@ def __init__(self):
7171

7272
def on_publish(
7373
self,
74-
path: str = "/default/*",
74+
path: str = DEFAULT_ROUTE,
7575
aggregate: bool = False,
7676
) -> Callable:
7777
"""
@@ -113,7 +113,7 @@ def on_publish(
113113

114114
def async_on_publish(
115115
self,
116-
path: str = "/default/*",
116+
path: str = DEFAULT_ROUTE,
117117
aggregate: bool = False,
118118
) -> Callable:
119119
"""
@@ -154,7 +154,7 @@ def async_on_publish(
154154

155155
def on_subscribe(
156156
self,
157-
path: str = "/default/*",
157+
path: str = DEFAULT_ROUTE,
158158
) -> Callable:
159159
"""
160160
Register a resolver function for subscribe operations.

tests/functional/event_handler/required_dependencies/appsync/test_appsync_events_resolvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ async def process_order(order_id, product_id, quantity):
10411041
return {
10421042
"order_id": order_id,
10431043
"status": "processed",
1044-
"total_amount": quantity * 10.99,
1044+
"total_amount": quantity * 10,
10451045
}
10461046

10471047
order_service = MockOrderService()
@@ -1070,7 +1070,7 @@ async def process_order(payload):
10701070
assert result["events"][0]["payload"]["order_processed"] is True
10711071
assert result["events"][0]["payload"]["order_details"]["order_id"] == "order-123"
10721072
assert result["events"][0]["payload"]["order_details"]["status"] == "processed"
1073-
assert result["events"][0]["payload"]["order_details"]["total_amount"] == 21.98 # 2 * 10.99
1073+
assert result["events"][0]["payload"]["order_details"]["total_amount"] == 20 # 2 * 10
10741074

10751075

10761076
def test_complex_resolver_hierarchy(lambda_context, mock_event):

0 commit comments

Comments
 (0)