aqlgen_renderer/document_wrapper/
mutations_type_wrapper.rs

1use async_graphql_parser::types::{ObjectType, TypeDefinition};
2
3use super::{
4    Context, Dependency, FileRender, MutationTypeWrapper, RenderType, SupportField, SupportTypeName,
5};
6
7#[derive(Debug)]
8pub struct MutationsTypeWrapper<'a, 'b> {
9    pub doc: &'a TypeDefinition,
10    pub object: &'a ObjectType,
11    pub context: &'a Context<'b>,
12}
13
14impl<'a, 'b> FileRender for MutationsTypeWrapper<'a, 'b> {
15    fn super_module_name(&self) -> String {
16        "mutations_type".to_string()
17    }
18}
19
20impl<'a, 'b> RenderType for MutationsTypeWrapper<'a, 'b> {
21    #[must_use]
22    fn gql_name(&self) -> String {
23        self.doc.name.node.to_string()
24    }
25
26    #[must_use]
27    fn description(&self) -> Option<&String> {
28        match &self.doc.description {
29            Some(_f) => panic!("Not Implemented"),
30            _ => None,
31        }
32    }
33}
34
35impl<'a, 'b> MutationsTypeWrapper<'a, 'b> {
36    #[must_use]
37    pub fn mutations(&self) -> Vec<MutationTypeWrapper> {
38        self.object
39            .fields
40            .iter()
41            .map(|f| MutationTypeWrapper {
42                doc: &f.node,
43                context: self.context,
44            })
45            .collect()
46    }
47
48    pub fn dependencies(&self) -> Vec<Dependency> {
49        let mut deps: Vec<Dependency> = self
50            .mutations()
51            .iter()
52            .flat_map(|f| f.dependencies())
53            .collect();
54
55        let arg_deps: Vec<Dependency> = self
56            .mutations()
57            .iter()
58            .flat_map(|f| f.arguments_dependencies())
59            .collect();
60        deps.extend(arg_deps);
61        deps
62    }
63}