bluejay_visibility/
input_value_definition.rs1use crate::{Cache, Directives, InputType, Warden};
2use bluejay_core::definition::{self, HasDirectives, SchemaDefinition};
3
4pub struct InputValueDefinition<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> {
5 inner: &'a S::InputValueDefinition,
6 r#type: InputType<'a, S, W>,
7 directives: Option<Directives<'a, S, W>>,
8 cache: &'a Cache<'a, S, W>,
9}
10
11impl<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> InputValueDefinition<'a, S, W> {
12 pub(crate) fn new(
13 inner: &'a S::InputValueDefinition,
14 cache: &'a Cache<'a, S, W>,
15 ) -> Option<Self> {
16 cache
17 .warden()
18 .is_input_value_definition_visible(inner)
19 .then(|| {
20 InputType::new(definition::InputValueDefinition::r#type(inner), cache).map(
21 |r#type| Self {
22 inner,
23 r#type,
24 directives: inner.directives().map(|d| Directives::new(d, cache)),
25 cache,
26 },
27 )
28 })
29 .flatten()
30 }
31
32 pub fn inner(&self) -> &'a S::InputValueDefinition {
33 self.inner
34 }
35
36 pub fn cache(&self) -> &'a Cache<'a, S, W> {
37 self.cache
38 }
39}
40
41impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>> definition::InputValueDefinition
42 for InputValueDefinition<'a, S, W>
43{
44 type Value = <S::InputValueDefinition as definition::InputValueDefinition>::Value;
45 type InputType = InputType<'a, S, W>;
46
47 fn description(&self) -> Option<&str> {
48 self.inner.description()
49 }
50
51 fn name(&self) -> &str {
52 self.inner.name()
53 }
54
55 fn default_value(&self) -> Option<&Self::Value> {
56 self.cache
57 .warden()
58 .input_value_definition_default_value(self)
59 }
60
61 fn r#type(&self) -> &Self::InputType {
62 &self.r#type
63 }
64}
65
66impl<'a, S: SchemaDefinition + 'a, W: Warden<SchemaDefinition = S>> HasDirectives
67 for InputValueDefinition<'a, S, W>
68{
69 type Directives = Directives<'a, S, W>;
70
71 fn directives(&self) -> Option<&Self::Directives> {
72 self.directives.as_ref()
73 }
74}