1 unstable release
new 0.1.0 | Mar 30, 2025 |
---|
#5 in #appsync
Used in lambda-appsync
61KB
1.5K
SLoC
This crate provides procedural macros for implementing AWS AppSync Direct Lambda resolvers.
It helps convert GraphQL schemas into type-safe Rust code with full AWS Lambda runtime support.
The main functionality is provided through the appsync_lambda_main
and appsync_operation
macros.
Complete Example
use lambda_appsync::{appsync_lambda_main, appsync_operation, AppsyncError, ID};
// 1. First define your GraphQL schema (e.g. `schema.graphql`):
//
// type Query {
// players: [Player!]!
// gameStatus: GameStatus!
// }
//
// type Player {
// id: ID!
// name: String!
// team: Team!
// }
//
// enum Team {
// RUST
// PYTHON
// JS
// }
//
// enum GameStatus {
// STARTED
// STOPPED
// }
// 2. Initialize the Lambda runtime with AWS SDK clients in main.rs:
// Optional hook for custom request validation/auth
async fn verify_request(
event: &lambda_appsync::AppsyncEvent<Operation>
) -> Option<lambda_appsync::AppsyncResponse> {
// Return Some(response) to short-circuit normal execution
None
}
// Generate types and runtime setup from schema
appsync_lambda_main!(
"schema.graphql",
// Initialize DynamoDB client if needed
dynamodb() -> aws_sdk_dynamodb::Client,
// Enable validation hook
hook = verify_request,
// Enable batch processing
batch = true
);
// 3. Implement resolver functions for GraphQL operations:
#[appsync_operation(query(players))]
async fn get_players() -> Result<Vec<Player>, AppsyncError> {
let client = dynamodb();
todo!()
}
#[appsync_operation(query(gameStatus))]
async fn get_game_status() -> Result<GameStatus, AppsyncError> {
let client = dynamodb();
todo!()
}
// The macro ensures the function signature matches the GraphQL schema
// and wires everything up to handle AWS AppSync requests automatically
Dependencies
~1–1.5MB
~35K SLoC