async-graphql 0.5.0

The GraphQL server library implemented by rust
Documentation
use crate::model::__Type;
use crate::{registry, Context, Result};
use async_graphql_derive::Object;

#[Object(
    internal,
    desc = "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.",
    field(name = "name", type = "String", owned),
    field(name = "description", type = "Option<String>", owned),
    field(name = "type", resolver = "ty", type = "__Type", owned),
    field(name = "isDeprecated", type = "bool", owned),
    field(name = "deprecationReason", type = "Option<String>", owned)
)]
pub struct __Field<'a> {
    pub registry: &'a registry::Registry,
    pub field: &'a registry::Field,
}

#[async_trait::async_trait]
#[allow()]
impl<'a> __FieldFields for __Field<'a> {
    async fn name(&self, _: &Context<'_>) -> Result<String> {
        Ok(self.field.name.to_string())
    }

    async fn description(&self, _: &Context<'_>) -> Result<Option<String>> {
        Ok(self.field.description.map(|s| s.to_string()))
    }

    async fn ty<'b>(&'b self, _: &Context<'_>) -> Result<__Type<'b>> {
        Ok(__Type {
            registry: self.registry,
            ty: &self.registry[&self.field.ty],
        })
    }

    async fn is_deprecated(&self, _: &Context<'_>) -> Result<bool> {
        Ok(self.field.deprecation.is_some())
    }

    async fn deprecation_reason(&self, _: &Context<'_>) -> Result<Option<String>> {
        Ok(self.field.deprecation.map(|s| s.to_string()))
    }
}