Skip to content

Commit ec4fcd7

Browse files
committed
docs(appsync): improve typing and tracing for nested mappings snippet
1 parent 0b6f9b6 commit ec4fcd7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docs/core/event_handler/appsync.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ You can nest `app.resolver()` decorator multiple times when resolving fields wit
108108

109109
=== "nested_mappings.py"
110110

111-
```python hl_lines="2 8 11-12 14 21"
111+
```python hl_lines="2 8 18-19 21 28"
112112
--8<-- "examples/event_handler_graphql/src/nested_mappings.py"
113113
```
114114

examples/event_handler_graphql/src/nested_mappings.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TypedDict
2+
13
from aws_lambda_powertools import Logger, Tracer
24
from aws_lambda_powertools.event_handler import AppSyncResolver
35
from aws_lambda_powertools.logging import correlation_paths
@@ -8,11 +10,18 @@
810
app = AppSyncResolver()
911

1012

13+
class Location(TypedDict):
14+
id: str # noqa AA03 VNE003, required due to GraphQL Schema
15+
name: str
16+
description: str
17+
address: str
18+
19+
1120
@app.resolver(field_name="listLocations")
1221
@app.resolver(field_name="locations")
1322
@tracer.capture_method
14-
def get_locations(name: str, description: str = ""): # match GraphQL Query arguments
15-
return name + description
23+
def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments
24+
return [{"name": name, "description": description}]
1625

1726

1827
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)

0 commit comments

Comments
 (0)