Skip to main content

DbResolver

Trait DbResolver 

Source
pub trait DbResolver: Send + Sync {
    // Required method
    fn resolve_query(
        &self,
        ctx: &ResolverContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send>>;

    // Provided method
    fn resolve_mutation(
        &self,
        ctx: &ResolverContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send>> { ... }
}
Expand description

DB Resolver trait — P2-1 修复 C-3

调用方实现此 trait,为 GraphQL root field 提供真实数据。

§方法

  • resolve_query:解析 Query 字段,返回单个对象或数组
  • resolve_mutation:解析 Mutation 字段,返回操作结果

§async 实现

使用 Pin<Box<dyn Future>> 返回异步结果,无需 async-trait 依赖。

Required Methods§

Source

fn resolve_query( &self, ctx: &ResolverContext, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send>>

解析 Query root field

§参数
  • ctx:resolver 上下文(字段名、参数等)
§返回
  • Ok(Value):解析结果(单个对象为 Value::Object,列表为 Value::Array
  • Err(String):解析错误

Provided Methods§

Source

fn resolve_mutation( &self, ctx: &ResolverContext, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send>>

解析 Mutation root field

默认实现返回错误,调用方按需覆盖。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§