grafbase_sdk/types/
directive.rs1use serde::Deserialize;
2
3use crate::{cbor, wit, SdkError};
4
5use super::FieldDefinitionDirectiveSite;
6
7pub struct SchemaDirective(wit::SchemaDirective);
9
10impl SchemaDirective {
11 #[inline]
13 pub fn name(&self) -> &str {
14 &self.0.name
15 }
16
17 #[inline]
19 pub fn subgraph_name(&self) -> &str {
20 &self.0.subgraph_name
21 }
22
23 #[inline]
28 pub fn arguments<'de, T>(&'de self) -> Result<T, SdkError>
29 where
30 T: Deserialize<'de>,
31 {
32 cbor::from_slice(&self.0.arguments).map_err(Into::into)
33 }
34}
35
36impl From<wit::SchemaDirective> for SchemaDirective {
37 fn from(value: wit::SchemaDirective) -> Self {
38 Self(value)
39 }
40}
41
42pub struct FieldDefinitionDirective<'a>(&'a wit::FieldDefinitionDirective);
44
45impl<'a> FieldDefinitionDirective<'a> {
46 #[inline]
48 pub fn name(&self) -> &str {
49 &self.0.name
50 }
51
52 pub fn arguments<T>(&self) -> Result<T, SdkError>
55 where
56 T: Deserialize<'a>,
57 {
58 self.site().arguments()
59 }
60
61 #[inline]
63 pub fn site(&self) -> FieldDefinitionDirectiveSite<'a> {
64 (&self.0.site).into()
65 }
66}
67
68impl<'a> From<&'a wit::FieldDefinitionDirective> for FieldDefinitionDirective<'a> {
69 fn from(value: &'a wit::FieldDefinitionDirective) -> Self {
70 Self(value)
71 }
72}