From 17c820d9652033951aadadbc4682dfc9b0676333 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 3 Jul 2025 20:58:57 +0200 Subject: [PATCH 1/2] docs(event-handler): remove Amplify transformers section --- docs/core/event_handler/appsync.md | 53 +------------------ ...amplify_graphql_transformer_schema.graphql | 23 -------- .../src/graphql_transformer_common_field.json | 17 ------ .../graphql_transformer_find_merchant.json | 19 ------- .../graphql_transformer_list_locations.json | 22 -------- .../src/graphql_transformer_merchant_info.py | 36 ------------- .../graphql_transformer_search_merchant.py | 42 --------------- 7 files changed, 2 insertions(+), 210 deletions(-) delete mode 100644 examples/event_handler_graphql/src/amplify_graphql_transformer_schema.graphql delete mode 100644 examples/event_handler_graphql/src/graphql_transformer_common_field.json delete mode 100644 examples/event_handler_graphql/src/graphql_transformer_find_merchant.json delete mode 100644 examples/event_handler_graphql/src/graphql_transformer_list_locations.json delete mode 100644 examples/event_handler_graphql/src/graphql_transformer_merchant_info.py delete mode 100644 examples/event_handler_graphql/src/graphql_transformer_search_merchant.py diff --git a/docs/core/event_handler/appsync.md b/docs/core/event_handler/appsync.md index a006a3f1415..7cd766a28dd 100644 --- a/docs/core/event_handler/appsync.md +++ b/docs/core/event_handler/appsync.md @@ -3,7 +3,7 @@ title: GraphQL API description: Core utility --- -Event Handler for AWS AppSync and Amplify GraphQL Transformer. +Event Handler for AWS AppSync GraphQL APIs simplifies routing and processing of events in AWS Lambda functions. It allows you to define resolvers for GraphQL types and fields, making it easier to handle GraphQL requests without the need for complex VTL or JavaScript templates. ```mermaid stateDiagram-v2 @@ -46,7 +46,7 @@ stateDiagram-v2 **[Direct Lambda Resolver](https://docs.aws.amazon.com/appsync/latest/devguide/direct-lambda-reference.html){target="_blank"}**. A custom AppSync Resolver to bypass the use of Apache Velocity Template (VTL) and automatically map your function's response to a GraphQL field. -**[Amplify GraphQL Transformer](https://docs.amplify.aws/cli/graphql-transformer/function){target="_blank"}**. Custom GraphQL directives to define your application's data model using Schema Definition Language _(SDL)_, _e.g., `@function`_. Amplify CLI uses these directives to convert GraphQL SDL into full descriptive AWS CloudFormation templates. +**[Batching resolvers](https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html#advanced-use-case-batching){target="_blank"}**. A technique that allows you to batch multiple GraphQL requests into a single Lambda function invocation, reducing the number of calls and improving performance. ## Getting started @@ -170,55 +170,6 @@ For Lambda Python3.8+ runtime, this utility supports async functions when you us --8<-- "examples/event_handler_graphql/src/async_resolvers.py" ``` -### Amplify GraphQL Transformer - -Assuming you have [Amplify CLI installed](https://docs.amplify.aws/cli/start/install){target="_blank"}, create a new API using `amplify add api` and use the following GraphQL Schema. - - - -```typescript hl_lines="7 15 20 22" title="Example GraphQL Schema" ---8<-- "examples/event_handler_graphql/src/amplify_graphql_transformer_schema.graphql" -``` - -[Create two new basic Python functions](https://docs.amplify.aws/cli/function#set-up-a-function){target="_blank"} via `amplify add function`. - -???+ note - Amplify CLI generated functions use `Pipenv` as a dependency manager. Your function source code is located at **`amplify/backend/function/your-function-name`**. - -Within your function's folder, add Powertools for AWS Lambda (Python) as a dependency with `pipenv install aws-lambda-powertools`. - -Use the following code for `merchantInfo` and `searchMerchant` functions respectively. - -=== "graphql_transformer_merchant_info.py" - - ```python hl_lines="4 6 23 24 29 30 36" - --8<-- "examples/event_handler_graphql/src/graphql_transformer_merchant_info.py" - ``` - -=== "graphql_transformer_search_merchant.py" - - ```python hl_lines="4 6 21 22 36 42" - --8<-- "examples/event_handler_graphql/src/graphql_transformer_search_merchant.py" - ``` - -=== "graphql_transformer_list_locations.json" - - ```json hl_lines="2-7" - --8<-- "examples/event_handler_graphql/src/graphql_transformer_list_locations.json" - ``` - -=== "graphql_transformer_common_field.json" - - ```json hl_lines="2 3" - --8<-- "examples/event_handler_graphql/src/graphql_transformer_common_field.json" - ``` - -=== "graphql_transformer_find_merchant.json" - - ```json hl_lines="2-6" - --8<-- "examples/event_handler_graphql/src/graphql_transformer_find_merchant.json" - ``` - ### Custom data models You can subclass [AppSyncResolverEvent](../../utilities/data_classes.md#appsync-resolver){target="_blank"} to bring your own set of methods to handle incoming events, by using `data_model` param in the `resolve` method. diff --git a/examples/event_handler_graphql/src/amplify_graphql_transformer_schema.graphql b/examples/event_handler_graphql/src/amplify_graphql_transformer_schema.graphql deleted file mode 100644 index 0bd6949cb91..00000000000 --- a/examples/event_handler_graphql/src/amplify_graphql_transformer_schema.graphql +++ /dev/null @@ -1,23 +0,0 @@ -@model -type Merchant { - id: String! - name: String! - description: String - # Resolves to `common_field` - commonField: String @function(name: "merchantInfo-${env}") -} - -type Location { - id: ID! - name: String! - address: String - # Resolves to `common_field` - commonField: String @function(name: "merchantInfo-${env}") -} - -type Query { - # List of locations resolves to `list_locations` - listLocations(page: Int, size: Int): [Location] @function(name: "merchantInfo-${env}") - # List of locations resolves to `list_locations` - findMerchant(search: str): [Merchant] @function(name: "searchMerchant-${env}") -} diff --git a/examples/event_handler_graphql/src/graphql_transformer_common_field.json b/examples/event_handler_graphql/src/graphql_transformer_common_field.json deleted file mode 100644 index 6b8b47b8172..00000000000 --- a/examples/event_handler_graphql/src/graphql_transformer_common_field.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "typeName": "Merchant", - "fieldName": "commonField", - "arguments": {}, - "identity": { - "claims": { - "iat": 1615366261 - }, - "username": "marieellis" - }, - "request": { - "headers": { - "x-amzn-trace-id": "Root=1-60488877-0b0c4e6727ab2a1c545babd0", - "x-forwarded-for": "127.0.0.1" - } - }, -} \ No newline at end of file diff --git a/examples/event_handler_graphql/src/graphql_transformer_find_merchant.json b/examples/event_handler_graphql/src/graphql_transformer_find_merchant.json deleted file mode 100644 index 8186ebc110e..00000000000 --- a/examples/event_handler_graphql/src/graphql_transformer_find_merchant.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "typeName": "Query", - "fieldName": "findMerchant", - "arguments": { - "search": "Parry-Wood" - }, - "identity": { - "claims": { - "iat": 1615366261 - }, - "username": "wwilliams" - }, - "request": { - "headers": { - "x-amzn-trace-id": "Root=1-60488877-0b0c4e6727ab2a1c545babd0", - "x-forwarded-for": "127.0.0.1" - } - }, -} \ No newline at end of file diff --git a/examples/event_handler_graphql/src/graphql_transformer_list_locations.json b/examples/event_handler_graphql/src/graphql_transformer_list_locations.json deleted file mode 100644 index b8f24aa70b6..00000000000 --- a/examples/event_handler_graphql/src/graphql_transformer_list_locations.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "typeName": "Query", - "fieldName": "listLocations", - "arguments": { - "page": 2, - "size": 1 - }, - "identity": { - "claims": { - "iat": 1615366261 - }, - "username": "treid" - }, - "request": { - "headers": { - "x-amzn-trace-id": "Root=1-60488877-0b0c4e6727ab2a1c545babd0", - "x-forwarded-for": "127.0.0.1", - "cloudfront-viewer-country": "NL", - "x-api-key": "da1-c33ullkbkze3jg5hf5ddgcs4fq" - } - } -} \ No newline at end of file diff --git a/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py b/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py deleted file mode 100644 index ec751882fe3..00000000000 --- a/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py +++ /dev/null @@ -1,36 +0,0 @@ -from typing import List, TypedDict - -from aws_lambda_powertools import Logger, Tracer -from aws_lambda_powertools.event_handler import AppSyncResolver -from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.data_classes.appsync import scalar_types_utils -from aws_lambda_powertools.utilities.typing import LambdaContext - -tracer = Tracer() -logger = Logger() -app = AppSyncResolver() - - -class Location(TypedDict, total=False): - id: str # noqa AA03 VNE003, required due to GraphQL Schema - name: str - description: str - address: str - commonField: str - - -@app.resolver(type_name="Query", field_name="listLocations") -def list_locations(page: int = 0, size: int = 10) -> List[Location]: - return [{"id": scalar_types_utils.make_id(), "name": "Smooth Grooves"}] - - -@app.resolver(field_name="commonField") -def common_field() -> str: - # Would match all fieldNames matching 'commonField' - return scalar_types_utils.make_id() - - -@tracer.capture_lambda_handler -@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER) -def lambda_handler(event: dict, context: LambdaContext) -> dict: - return app.resolve(event, context) diff --git a/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py b/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py deleted file mode 100644 index 895b1f539e2..00000000000 --- a/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py +++ /dev/null @@ -1,42 +0,0 @@ -from typing import List, TypedDict - -from aws_lambda_powertools import Logger, Tracer -from aws_lambda_powertools.event_handler import AppSyncResolver -from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.data_classes.appsync import scalar_types_utils -from aws_lambda_powertools.utilities.typing import LambdaContext - -app = AppSyncResolver() -tracer = Tracer() -logger = Logger() - - -class Merchant(TypedDict, total=False): - id: str # noqa AA03 VNE003, required due to GraphQL Schema - name: str - description: str - commonField: str - - -@app.resolver(type_name="Query", field_name="findMerchant") -def find_merchant(search: str) -> List[Merchant]: - merchants: List[Merchant] = [ - { - "id": scalar_types_utils.make_id(), - "name": "Parry-Wood", - "description": "Possimus doloremque tempora harum deleniti eum.", - }, - { - "id": scalar_types_utils.make_id(), - "name": "Shaw, Owen and Jones", - "description": "Aliquam iste architecto suscipit in.", - }, - ] - - return [merchant for merchant in merchants if search == merchant["name"]] - - -@tracer.capture_lambda_handler -@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER) -def lambda_handler(event: dict, context: LambdaContext) -> dict: - return app.resolve(event, context) From e94c97c32c82d535d81f7b71cb62e996db6adf33 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 3 Jul 2025 23:43:46 +0200 Subject: [PATCH 2/2] Update appsync.md Co-authored-by: Leandro Damascena Signed-off-by: Andrea Amorosi --- docs/core/event_handler/appsync.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/event_handler/appsync.md b/docs/core/event_handler/appsync.md index 7cd766a28dd..6a3650908be 100644 --- a/docs/core/event_handler/appsync.md +++ b/docs/core/event_handler/appsync.md @@ -3,7 +3,7 @@ title: GraphQL API description: Core utility --- -Event Handler for AWS AppSync GraphQL APIs simplifies routing and processing of events in AWS Lambda functions. It allows you to define resolvers for GraphQL types and fields, making it easier to handle GraphQL requests without the need for complex VTL or JavaScript templates. +Event Handler for AWS AppSync GraphQL APIs simplifies routing and processing of events in AWS Lambda functions by allowing you to define resolvers for specific GraphQL types and fields. ```mermaid stateDiagram-v2