async_graphql/
custom_directive.rs1use std::borrow::Cow;
2
3use crate::{
4 extensions::ResolveFut, parser::types::Directive, registry::Registry, Context,
5 ContextDirective, ServerResult, Value,
6};
7
8#[doc(hidden)]
9pub trait CustomDirectiveFactory: Send + Sync + 'static {
10 fn name(&self) -> Cow<'static, str>;
11
12 fn register(&self, registry: &mut Registry);
13
14 fn create(
15 &self,
16 ctx: &ContextDirective<'_>,
17 directive: &Directive,
18 ) -> ServerResult<Box<dyn CustomDirective>>;
19}
20
21#[doc(hidden)]
22pub trait TypeDirective {
24 fn name(&self) -> Cow<'static, str>;
25
26 fn register(&self, registry: &mut Registry);
27}
28
29#[async_trait::async_trait]
31#[allow(unused_variables)]
32pub trait CustomDirective: Sync + Send + 'static {
33 async fn resolve_field(
35 &self,
36 ctx: &Context<'_>,
37 resolve: ResolveFut<'_>,
38 ) -> ServerResult<Option<Value>> {
39 resolve.await
40 }
41}