lambda-appsync-proc 0.3.0

Procedural macros for the lambda-appsync type-safe AWS AppSync resolver framework
Documentation

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};

// 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,
#   exclude_lambda_handler = true,
);
# fn dynamodb() -> aws_sdk_dynamodb::Client {todo!()}
# fn main() {}
// 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