reinhardt_graphql/lib.rs
1//! GraphQL support for Reinhardt framework
2//!
3//! This crate provides GraphQL API support for the Reinhardt framework.
4//!
5//! # Features
6//!
7//! - **graphql-grpc**: GraphQL facade over gRPC for Query/Mutation
8//! - **subscription**: gRPC-based Subscriptions (Rust 2024 compatible)
9//! - **di**: Dependency injection support for GraphQL resolvers
10//! - **full**: All features enabled
11//!
12//! # Dependency Injection
13//!
14//! Enable the `di` feature to use dependency injection in GraphQL resolvers:
15//!
16//! ```toml
17//! [dependencies]
18//! reinhardt-graphql = { version = "0.1", features = ["di"] }
19//! ```
20//!
21//! Then use the `#[graphql_handler]` macro:
22//!
23//! ```rust,no_run
24//! # use async_graphql::{Context, Object, Result, ID, SimpleObject};
25//! # use reinhardt_graphql::{graphql_handler, GraphQLContextExt};
26//! # use reinhardt_di::{InjectionContext, Injectable, DiResult};
27//! # use async_trait::async_trait;
28//! #
29//! # #[derive(Clone, SimpleObject)]
30//! # struct User {
31//! # id: ID,
32//! # name: String,
33//! # }
34//! #
35//! # #[derive(Clone)]
36//! # struct DatabaseConnection;
37//! #
38//! # #[async_trait]
39//! # impl Injectable for DatabaseConnection {
40//! # async fn inject(_ctx: &InjectionContext) -> DiResult<Self> {
41//! # Ok(DatabaseConnection)
42//! # }
43//! # }
44//! #
45//! # impl DatabaseConnection {
46//! # async fn fetch_user(&self, id: &ID) -> Result<User> {
47//! # Ok(User { id: id.clone(), name: "Test User".to_string() })
48//! # }
49//! # }
50//! #
51//! # struct Query;
52//! #
53//! #[Object]
54//! impl Query {
55//! async fn user(&self, ctx: &Context<'_>, id: ID) -> Result<User> {
56//! user_impl(ctx, id).await
57//! }
58//! }
59//!
60//! #[graphql_handler]
61//! async fn user_impl(
62//! ctx: &Context<'_>,
63//! id: ID,
64//! #[inject] db: DatabaseConnection,
65//! ) -> Result<User> {
66//! // db is automatically resolved
67//! db.fetch_user(&id).await
68//! }
69//! ```
70
71pub mod context;
72pub mod resolvers;
73pub mod schema;
74pub mod subscription;
75pub mod types;
76
77#[cfg(feature = "di")]
78pub mod di;
79
80#[cfg(feature = "graphql-grpc")]
81pub mod grpc_service;
82
83pub use context::{ContextError, DataLoader, GraphQLContext, LoaderError};
84pub use schema::{
85 AppSchema, CreateUserInput, Mutation, Query, QueryLimits, User, UserStorage, create_schema,
86 create_schema_with_limits, validate_query,
87};
88pub use subscription::{DEFAULT_CHANNEL_CAPACITY, EventBroadcaster, SubscriptionRoot, UserEvent};
89
90#[cfg(feature = "graphql-grpc")]
91pub use grpc_service::GraphQLGrpcService;
92
93// gRPC integration: re-export of adapter traits and derive macros
94#[cfg(any(feature = "graphql-grpc", feature = "subscription"))]
95pub use reinhardt_grpc::{GrpcServiceAdapter, GrpcSubscriptionAdapter};
96
97#[cfg(any(feature = "graphql-grpc", feature = "subscription"))]
98pub use reinhardt_graphql_macros::{GrpcGraphQLConvert, GrpcSubscription};
99
100// DI support: re-export extension traits and macro
101#[cfg(feature = "di")]
102pub use di::{GraphQLContextExt, SchemaBuilderExt};
103
104#[cfg(feature = "di")]
105pub use reinhardt_graphql_macros::graphql_handler;