Expand description
GraphQL support for Reinhardt framework
This crate provides GraphQL API support for the Reinhardt framework.
§Features
- graphql-grpc: GraphQL facade over gRPC for Query/Mutation
- subscription: gRPC-based Subscriptions (Rust 2024 compatible)
- di: Dependency injection support for GraphQL resolvers
- full: All features enabled
§Dependency Injection
Enable the di feature to use dependency injection in GraphQL resolvers:
[dependencies]
reinhardt-graphql = { version = "0.1", features = ["di"] }Then use the #[graphql_handler] macro:
#[Object]
impl Query {
async fn user(&self, ctx: &Context<'_>, id: ID) -> Result<User> {
user_impl(ctx, id).await
}
}
#[graphql_handler]
async fn user_impl(
ctx: &Context<'_>,
id: ID,
#[inject] db: DatabaseConnection,
) -> Result<User> {
// db is automatically resolved
db.fetch_user(&id).await
}Re-exports§
pub use context::ContextError;pub use context::DataLoader;pub use context::GraphQLContext;pub use context::LoaderError;pub use schema::AppSchema;pub use schema::CreateUserInput;pub use schema::Mutation;pub use schema::Query;pub use schema::QueryLimits;pub use schema::User;pub use schema::UserStorage;pub use schema::create_schema;pub use schema::create_schema_with_limits;pub use schema::validate_query;pub use subscription::DEFAULT_CHANNEL_CAPACITY;pub use subscription::EventBroadcaster;pub use subscription::SubscriptionRoot;pub use subscription::UserEvent;pub use di::GraphQLContextExt;pub use di::SchemaBuilderExt;
Modules§
- context
- GraphQL execution context and data loaders. GraphQL context for request-scoped data
- di
- Dependency injection integration for GraphQL handlers. Dependency injection support for GraphQL resolvers
- http
- Re-export of
async_graphql::httpmodule for HTTP integration utilities such asplayground_sourceandGraphQLPlaygroundConfig. A helper module that supports HTTP - resolvers
- Resolver implementations for queries and mutations. GraphQL resolvers
- schema
- Schema definition, query limits, and built-in types.
- subscription
- Real-time GraphQL subscriptions with event broadcasting.
- types
- GraphQL scalar and input type definitions. GraphQL type definitions
Structs§
- Error
- An error with a message and optional extensions.
- ID
- ID scalar
- Request
- GraphQL request.
- Schema
- GraphQL schema.
Traits§
- Error
Extensions - An error which can be extended into a
Error.
Type Aliases§
- Context
- Context object for resolve field
- Field
Error - An alias of async_graphql::Error. Present for backward compatibility reasons.
- GqlResult
- An alias for
Result<T, Error>.
Attribute Macros§
- Object
- Subscription
- graphql_
handler - Attribute macro for GraphQL resolvers with dependency injection support