dynamic-graphql-derive 0.10.2

Dynamic GraphQL schema macro
Documentation
use darling::FromGenerics;

use crate::FromItemImpl;
use crate::utils::impl_block::BaseMethod;
use crate::utils::impl_block::FromImplItemFn;
use crate::utils::impl_block::Methods;
use crate::utils::with_context::SetContext;
use crate::utils::with_index::SetIndex;

#[derive(Debug, Clone)]
pub struct BaseItemImpl<Method = BaseMethod, Generics = ()> {
    #[allow(dead_code)]
    pub trait_: Option<syn::Path>,
    pub ty: syn::Type,
    pub methods: Methods<Method>,
    pub generics: Generics,
    // todo generics, consts, types
}

impl<Method, Generics> FromItemImpl for BaseItemImpl<Method, Generics>
where
    Method: FromImplItemFn + SetIndex,
    Generics: FromGenerics,
{
    fn from_item_impl(item_impl: &mut syn::ItemImpl) -> darling::Result<Self> {
        Ok(Self {
            trait_: item_impl.trait_.as_ref().map(|t| t.1.clone()),
            ty: item_impl.self_ty.as_ref().clone(),
            generics: FromGenerics::from_generics(&item_impl.generics)?,
            methods: Methods::from_impl_item_methods(&mut item_impl.items.iter_mut())?,
        })
    }
}

impl<Method, Generics> SetContext for BaseItemImpl<Method, Generics>
where
    Method: FromImplItemFn + SetContext,
{
    type Context = Method::Context;

    fn set_context(&mut self, context: Self::Context) {
        self.methods.set_context(context);
    }
}