Skip to main content

Crate reinhardt_graphql

Crate reinhardt_graphql 

Source
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

§GraphQL over gRPC

Each RPC accepts only its advertised query, mutation, or subscription operation. The adapter returns gRPC INVALID_ARGUMENT for malformed documents, invalid or ambiguous operation selections, and operation-class mismatches before execution. Documents with multiple operations require an exact operation name. A single operation may omit the name or pass an empty name. Schema validation and resolver authorization still apply after this transport-level check. Subscription errors are delivered through the response stream.

Build custom gRPC schemas with GraphQLGrpcService::schema_builder instead of Schema::build / Schema::new. This installs the operation guard before user extensions, so preparation limits and document rewrites run in their normal order. GraphQLGrpcService::new panics for unguarded schemas. The built-in create_schema helpers install the guard when graphql-grpc is 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::http module for HTTP integration utilities such as playground_source and GraphQLPlaygroundConfig. 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§

ErrorExtensions
An error which can be extended into a Error.

Type Aliases§

Context
Context object for resolve field
FieldError
An alias of async_graphql::Error. Present for backward compatibility reasons.
GqlResult
An alias for Result<T, Error>.

Attribute Macros§

Object
Define a GraphQL object with methods
Subscription
Define a GraphQL subscription
graphql_handler
Attribute macro for GraphQL resolvers with dependency injection support

Derive Macros§

Enum
Define a GraphQL enum
InputObject
Define a GraphQL input object
MergedObject
Define a merged object with multiple object types.
MergedSubscription
Define a merged subscription with multiple subscription types.
SimpleObject
Define a GraphQL object with fields