Expand description
This crate provides procedural macros and types 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
);
// 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
Re-exports§
pub use aws_config;
pub use env_logger;
pub use lambda_runtime;
pub use log;
pub use serde;
pub use serde_json;
pub use tokio;
Modules§
- subscription_
filters - GraphQL subscription filter implementation for AWS AppSync
Macros§
- appsync_
lambda_ main - Generates the code required to handle AWS AppSync Direct Lambda resolver events based on a GraphQL schema.
Structs§
- AWSDate
- AWS AppSync specific GraphQL scalar type implemented a String new-type
- AWSDate
Time - AWS AppSync specific GraphQL scalar type implemented a String new-type
- AWSEmail
- AWS AppSync specific GraphQL scalar type implemented a String new-type
- AWSPhone
- AWS AppSync specific GraphQL scalar type implemented a String new-type
- AWSTime
- AWS AppSync specific GraphQL scalar type implemented a String new-type
- AWSTimestamp
- AWS AppSync specific GraphQL scalar type implemented SystemTime new-type. Note that this type implements Copy
- AWSUrl
- AWS AppSync specific GraphQL scalar type implemented a String new-type
- Appsync
Error - Error type for AWS AppSync operations
- Appsync
Event - Represents a complete AWS AppSync event sent to a Lambda resolver.
- Appsync
Event Info - Metadata about an AppSync GraphQL operation execution.
- Appsync
Identity Cognito - Identity information for Cognito User Pools authenticated requests.
- Appsync
Identity Iam - Identity information for IAM-authenticated requests.
- Appsync
Identity Lambda - Identity information for Lambda-authorized requests.
- Appsync
Identity Oidc - Identity information for OIDC-authenticated requests.
- Appsync
Response - Response structure returned to AWS AppSync from a Lambda resolver.
- Cognito
Federated Identity - Cognito Identity Pool information for federated IAM authentication
- ID
- A custom UUID-based identifier type for AppSync GraphQL objects.
Enums§
- Appsync
Auth Strategy - Authorization strategy for AppSync operations.
- Appsync
Identity - Identity information for an AppSync request.
- Cognito
Identity Auth Type - Authentication type in a Cognito Identity Pool
Functions§
- arg_
from_ json - Extracts and deserializes a named argument from a JSON Value into the specified type
- res_
to_ json - Serializes a value into a JSON Value for AppSync responses
Attribute Macros§
- appsync_
operation - Marks an async function as an AWS AppSync resolver operation, binding it to a specific Query, Mutation or Subscription operation defined in the GraphQL schema.