async_graphql/dynamic/
input_value.rs1use super::{directive::to_meta_directive_invocation, Directive};
2use crate::{
3 dynamic::TypeRef,
4 registry::{Deprecation, MetaInputValue},
5 Value,
6};
7
8#[derive(Debug)]
10pub struct InputValue {
11 pub(crate) name: String,
12 pub(crate) description: Option<String>,
13 pub(crate) ty: TypeRef,
14 pub(crate) default_value: Option<Value>,
15 pub(crate) inaccessible: bool,
16 pub(crate) tags: Vec<String>,
17 pub(crate) directives: Vec<Directive>,
18 pub(crate) deprecation: Deprecation,
19}
20
21impl InputValue {
22 #[inline]
24 pub fn new(name: impl Into<String>, ty: impl Into<TypeRef>) -> Self {
25 Self {
26 name: name.into(),
27 description: None,
28 ty: ty.into(),
29 default_value: None,
30 inaccessible: false,
31 tags: Vec::new(),
32 directives: vec![],
33 deprecation: Deprecation::NoDeprecated,
34 }
35 }
36
37 impl_set_description!();
38 impl_set_inaccessible!();
39 impl_set_tags!();
40 impl_directive!();
41 impl_set_deprecation!();
42
43 #[inline]
45 pub fn default_value(self, value: impl Into<Value>) -> Self {
46 Self {
47 default_value: Some(value.into()),
48 ..self
49 }
50 }
51
52 pub(crate) fn to_meta_input_value(&self) -> MetaInputValue {
53 MetaInputValue {
54 name: self.name.clone(),
55 description: self.description.clone(),
56 ty: self.ty.to_string(),
57 deprecation: self.deprecation.clone(),
58 default_value: self
59 .default_value
60 .as_ref()
61 .map(std::string::ToString::to_string),
62 visible: None,
63 inaccessible: self.inaccessible,
64 tags: self.tags.clone(),
65 is_secret: false,
66 directive_invocations: to_meta_directive_invocation(self.directives.clone()),
67 }
68 }
69}