|
8 | 8 | from aws_lambda_powertools.utilities.data_classes import AppSyncResolverEvent
|
9 | 9 | from aws_lambda_powertools.utilities.typing import LambdaContext
|
10 | 10 | from aws_lambda_powertools.warnings import PowertoolsUserWarning
|
| 11 | +from tests.functional.utils import load_event |
11 | 12 |
|
12 | 13 |
|
13 | 14 | # TESTS RECEIVING THE EVENT PARTIALLY AND PROCESS EACH RECORD PER TIME.
|
@@ -710,7 +711,6 @@ def create_something(event: List[AppSyncResolverEvent]) -> List: # noqa AA03 VN
|
710 | 711 | assert result == [appsync_event["source"]["id"] for appsync_event in event]
|
711 | 712 |
|
712 | 713 | assert app.current_batch_event and len(app.current_batch_event) == len(event)
|
713 |
| - assert not app.current_event |
714 | 714 |
|
715 | 715 |
|
716 | 716 | def test_resolve_async_batch_processing_with_simple_queries_with_aggregate():
|
@@ -772,7 +772,6 @@ async def create_something(event: List[AppSyncResolverEvent]) -> List: # noqa A
|
772 | 772 | assert result == [appsync_event["source"]["id"] for appsync_event in event]
|
773 | 773 |
|
774 | 774 | assert app.current_batch_event and len(app.current_batch_event) == len(event)
|
775 |
| - assert not app.current_event |
776 | 775 |
|
777 | 776 |
|
778 | 777 | def test_resolve_batch_processing_with_aggregate_and_returning_a_non_list():
|
@@ -907,3 +906,40 @@ def do_something_with_post_id(post_id): ...
|
907 | 906 | # THEN the resolver should raise a InvalidBatchResponse when processing the batch of queries
|
908 | 907 | with pytest.raises(InvalidBatchResponse):
|
909 | 908 | app.resolve(event, LambdaContext())
|
| 909 | + |
| 910 | + |
| 911 | +def test_include_router_access_batch_current_event(): |
| 912 | + mock_event = load_event("appSyncBatchEvent.json") |
| 913 | + |
| 914 | + # GIVEN An instance of AppSyncResolver, a Router instance, and a resolver function registered with the router |
| 915 | + app = AppSyncResolver() |
| 916 | + router = Router() |
| 917 | + |
| 918 | + @router.batch_resolver(field_name="createSomething") |
| 919 | + def get_user(event: List) -> List: |
| 920 | + return [router.current_batch_event[0].identity.sub] |
| 921 | + |
| 922 | + app.include_router(router) |
| 923 | + |
| 924 | + # WHEN we resolve the event |
| 925 | + ret = app.resolve(mock_event, {}) |
| 926 | + |
| 927 | + # THEN the resolver must be able to return a field in the batch_current_event |
| 928 | + assert ret[0] == mock_event[0]["identity"]["sub"] |
| 929 | + |
| 930 | + |
| 931 | +def test_app_access_batch_current_event(): |
| 932 | + mock_event = load_event("appSyncBatchEvent.json") |
| 933 | + |
| 934 | + # GIVEN An instance of AppSyncResolver and a resolver function registered with the app |
| 935 | + app = AppSyncResolver() |
| 936 | + |
| 937 | + @app.batch_resolver(field_name="createSomething") |
| 938 | + def get_user(event: List) -> List: |
| 939 | + return [app.current_batch_event[0].identity.sub] |
| 940 | + |
| 941 | + # WHEN we resolve the event |
| 942 | + ret = app.resolve(mock_event, {}) |
| 943 | + |
| 944 | + # THEN the resolver must be able to return a field in the batch_current_event |
| 945 | + assert ret[0] == mock_event[0]["identity"]["sub"] |
0 commit comments