aqlgen_renderer/document_wrapper/
input_value_wrapper.rs1use super::Context;
2use async_graphql_parser::types::{InputValueDefinition, Type};
3use heck::ToSnakeCase;
4
5use super::{RenderType, SupportType, SupportTypeName, UseContext};
6
7#[derive(Debug, Clone)]
8pub struct InputValueWrapper<'a, 'b> {
9 pub doc: &'a InputValueDefinition,
10 pub context: &'a Context<'b>,
11}
12
13impl<'a, 'b> SupportType for InputValueWrapper<'a, 'b> {
14 fn ty(&self) -> &Type {
15 &self.doc.ty.node
16 }
17}
18
19impl<'a, 'b> RenderType for InputValueWrapper<'a, 'b> {
20 #[must_use]
21 fn gql_name(&self) -> String {
22 self.doc.name.node.to_string()
23 }
24
25 #[must_use]
26 fn description(&self) -> Option<&String> {
27 match &self.doc.description {
28 Some(_f) => panic!("Not Implemented"),
29 _ => None,
30 }
31 }
32}
33
34impl<'a, 'b> UseContext for InputValueWrapper<'a, 'b> {
35 fn context(&self) -> &Context {
36 self.context
37 }
38}
39
40impl<'a, 'b> SupportTypeName for InputValueWrapper<'a, 'b> {}
41
42impl<'a, 'b> InputValueWrapper<'a, 'b> {
43 #[must_use]
44 pub fn field_name(&self) -> String {
45 let name = self.name().to_snake_case();
46 if syn::parse_str::<syn::Ident>(&name).is_err() {
47 format!("_{}", name)
48 } else {
49 name
50 }
51 }
52}