aqlgen_renderer/document_wrapper/
field_wrapper.rs

1use super::Context;
2use async_graphql_parser::types::{FieldDefinition, InputValueDefinition, Type};
3
4use super::{RenderType, SupportField, SupportType, SupportTypeName, UseContext};
5
6#[derive(Debug, Clone)]
7pub struct FieldWrapper<'a, 'b> {
8    pub doc: &'a FieldDefinition,
9    pub context: &'a Context<'b>,
10}
11
12impl<'a, 'b> SupportType for FieldWrapper<'a, 'b> {
13    fn ty(&self) -> &Type {
14        &self.doc.ty.node
15    }
16}
17
18impl<'a, 'b> UseContext for FieldWrapper<'a, 'b> {
19    fn context(&self) -> &Context {
20        self.context
21    }
22}
23
24impl<'a, 'b> SupportField for FieldWrapper<'a, 'b> {
25    fn input_value_types(&self) -> Vec<&InputValueDefinition> {
26        let mut res = vec![];
27        self.doc.arguments.iter().for_each(|f| res.push(&f.node));
28        res
29    }
30}
31
32impl<'a, 'b> RenderType for FieldWrapper<'a, 'b> {
33    #[must_use]
34    fn gql_name(&self) -> String {
35        self.doc.name.node.to_string()
36    }
37
38    #[must_use]
39    fn description(&self) -> Option<&String> {
40        match &self.doc.description {
41            Some(f) => Some(&f.node),
42            _ => None,
43        }
44    }
45}
46
47impl<'a, 'b> SupportTypeName for FieldWrapper<'a, 'b> {}