/rust/registry/src/index.crates.io-6f17d22bba15001f/async-graphql-7.0.15/src/custom_directive.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use std::borrow::Cow; |
2 | | |
3 | | use crate::{ |
4 | | extensions::ResolveFut, parser::types::Directive, registry::Registry, Context, |
5 | | ContextDirective, ServerResult, Value, |
6 | | }; |
7 | | |
8 | | #[doc(hidden)] |
9 | | pub 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)] |
22 | | // minimal amount required to register directive into registry |
23 | | pub trait TypeDirective { |
24 | | fn name(&self) -> Cow<'static, str>; |
25 | | |
26 | | fn register(&self, registry: &mut Registry); |
27 | | } |
28 | | |
29 | | /// Represents a custom directive. |
30 | | #[async_trait::async_trait] |
31 | | #[allow(unused_variables)] |
32 | | pub trait CustomDirective: Sync + Send + 'static { |
33 | | /// Called at resolve field. |
34 | | async fn resolve_field( |
35 | | &self, |
36 | | ctx: &Context<'_>, |
37 | | resolve: ResolveFut<'_>, |
38 | 0 | ) -> ServerResult<Option<Value>> { |
39 | 0 | resolve.await |
40 | 0 | } |
41 | | } |