grafbase_sdk/types/
directive_site.rs

1use crate::wit;
2
3/// The site where a directive is applied in the GraphQL schema.
4pub enum DirectiveSite<'a> {
5    /// Directive applied to an object type
6    Object(ObjectDirectiveSite<'a>),
7    /// Directive applied to a field definition
8    FieldDefinition(FieldDefinitionDirectiveSite<'a>),
9    /// Directive applied to an interface
10    Interface(InterfaceDirectiveSite<'a>),
11    /// Directive applied to a union
12    Union(UnionDirectiveSite<'a>),
13    /// Directive applied to an enum
14    Enum(EnumDirectiveSite<'a>),
15    /// Directive applied to a scalar
16    Scalar(ScalarDirectiveSite<'a>),
17}
18
19impl<'a> From<&'a wit::DirectiveSite> for DirectiveSite<'a> {
20    fn from(value: &'a wit::DirectiveSite) -> Self {
21        match value {
22            wit::DirectiveSite::Object(site) => DirectiveSite::Object(site.into()),
23            wit::DirectiveSite::FieldDefinition(site) => DirectiveSite::FieldDefinition(site.into()),
24            wit::DirectiveSite::Interface(site) => DirectiveSite::Interface(site.into()),
25            wit::DirectiveSite::Union(site) => DirectiveSite::Union(site.into()),
26            wit::DirectiveSite::Enum(site) => DirectiveSite::Enum(site.into()),
27            wit::DirectiveSite::Scalar(site) => DirectiveSite::Scalar(site.into()),
28        }
29    }
30}
31
32/// A directive site for object types
33pub struct ObjectDirectiveSite<'a>(&'a wit::ObjectDirectiveSite);
34
35impl<'a> ObjectDirectiveSite<'a> {
36    /// The name of the object type
37    #[inline]
38    pub fn name(&self) -> &'a str {
39        &self.0.object_name
40    }
41}
42
43impl<'a> From<&'a wit::ObjectDirectiveSite> for ObjectDirectiveSite<'a> {
44    fn from(value: &'a wit::ObjectDirectiveSite) -> Self {
45        Self(value)
46    }
47}
48
49/// A directive site for field definitions
50pub struct FieldDefinitionDirectiveSite<'a>(&'a wit::FieldDefinitionDirectiveSite);
51
52impl<'a> FieldDefinitionDirectiveSite<'a> {
53    /// The name of the parent type containing this field
54    #[inline]
55    pub fn parent_type_name(&self) -> &'a str {
56        &self.0.parent_type_name
57    }
58
59    /// The name of the field
60    #[inline]
61    pub fn name(&self) -> &'a str {
62        &self.0.field_name
63    }
64}
65
66impl<'a> From<&'a wit::FieldDefinitionDirectiveSite> for FieldDefinitionDirectiveSite<'a> {
67    fn from(value: &'a wit::FieldDefinitionDirectiveSite) -> Self {
68        Self(value)
69    }
70}
71
72/// A directive site for union types
73pub struct UnionDirectiveSite<'a>(&'a wit::UnionDirectiveSite);
74
75impl<'a> UnionDirectiveSite<'a> {
76    /// The name of the union type
77    #[inline]
78    pub fn name(&self) -> &'a str {
79        &self.0.union_name
80    }
81}
82
83impl<'a> From<&'a wit::UnionDirectiveSite> for UnionDirectiveSite<'a> {
84    fn from(value: &'a wit::UnionDirectiveSite) -> Self {
85        Self(value)
86    }
87}
88
89/// A directive site for interfaces
90pub struct InterfaceDirectiveSite<'a>(&'a wit::InterfaceDirectiveSite);
91
92impl<'a> InterfaceDirectiveSite<'a> {
93    /// The name of the interface type
94    #[inline]
95    pub fn name(&self) -> &'a str {
96        &self.0.interface_name
97    }
98}
99
100impl<'a> From<&'a wit::InterfaceDirectiveSite> for InterfaceDirectiveSite<'a> {
101    fn from(value: &'a wit::InterfaceDirectiveSite) -> Self {
102        Self(value)
103    }
104}
105
106/// A directive site for scalars
107pub struct ScalarDirectiveSite<'a>(&'a wit::ScalarDirectiveSite);
108
109impl<'a> ScalarDirectiveSite<'a> {
110    /// The name of the scalar type
111    #[inline]
112    pub fn name(&self) -> &'a str {
113        &self.0.scalar_name
114    }
115}
116
117impl<'a> From<&'a wit::ScalarDirectiveSite> for ScalarDirectiveSite<'a> {
118    fn from(value: &'a wit::ScalarDirectiveSite) -> Self {
119        Self(value)
120    }
121}
122
123/// A directive site for enums
124pub struct EnumDirectiveSite<'a>(&'a wit::EnumDirectiveSite);
125
126impl<'a> EnumDirectiveSite<'a> {
127    /// The name of the enum type
128    #[inline]
129    pub fn name(&self) -> &'a str {
130        &self.0.enum_name
131    }
132}
133
134impl<'a> From<&'a wit::EnumDirectiveSite> for EnumDirectiveSite<'a> {
135    fn from(value: &'a wit::EnumDirectiveSite) -> Self {
136        Self(value)
137    }
138}