async_graphql/dynamic/
base.rs

1use crate::dynamic::{Field, InputValue, Interface, InterfaceField, Object, TypeRef};
2
3pub(crate) trait BaseField {
4    fn ty(&self) -> &TypeRef;
5
6    fn argument(&self, name: &str) -> Option<&InputValue>;
7}
8
9pub(crate) trait BaseContainer {
10    type FieldType: BaseField;
11
12    fn name(&self) -> &str;
13
14    fn graphql_type(&self) -> &str;
15
16    fn field(&self, name: &str) -> Option<&Self::FieldType>;
17}
18
19impl BaseField for Field {
20    #[inline]
21    fn ty(&self) -> &TypeRef {
22        &self.ty
23    }
24
25    #[inline]
26    fn argument(&self, name: &str) -> Option<&InputValue> {
27        self.arguments.get(name)
28    }
29}
30
31impl BaseContainer for Object {
32    type FieldType = Field;
33
34    #[inline]
35    fn name(&self) -> &str {
36        &self.name
37    }
38
39    fn graphql_type(&self) -> &str {
40        "Object"
41    }
42
43    #[inline]
44    fn field(&self, name: &str) -> Option<&Self::FieldType> {
45        self.fields.get(name)
46    }
47}
48
49impl BaseField for InterfaceField {
50    #[inline]
51    fn ty(&self) -> &TypeRef {
52        &self.ty
53    }
54
55    #[inline]
56    fn argument(&self, name: &str) -> Option<&InputValue> {
57        self.arguments.get(name)
58    }
59}
60
61impl BaseContainer for Interface {
62    type FieldType = InterfaceField;
63
64    #[inline]
65    fn name(&self) -> &str {
66        &self.name
67    }
68
69    fn graphql_type(&self) -> &str {
70        "Interface"
71    }
72
73    #[inline]
74    fn field(&self, name: &str) -> Option<&Self::FieldType> {
75        self.fields.get(name)
76    }
77}