Skip to main content

graphql_handler

Attribute Macro graphql_handler 

Source
#[graphql_handler]
Expand description

Attribute macro for GraphQL resolvers with dependency injection support

This macro enables the use of #[inject] parameters in GraphQL resolver functions, allowing automatic dependency resolution from the InjectionContext.

§Parameters

Regular parameters are passed through as-is. Parameters marked with #[inject] are automatically resolved from the DI context.

§Requirements

  1. The function must have an async_graphql::Context<'_> parameter
  2. The schema must have an InjectionContext in its data (use .data(injection_ctx))
  3. All injected types must implement Injectable
  4. The function must be async

§Error Handling

If dependency injection fails, the function returns async_graphql::Error with an error message describing the failure.