dynamic_graphql/
types.rs

1use std::borrow::Cow;
2
3use crate::registry::Registry;
4use crate::type_ref_builder::TypeRefBuilder;
5
6mod common;
7
8pub trait Register {
9    #[inline]
10    fn register(registry: Registry) -> Registry {
11        registry
12    }
13}
14
15pub trait RegisterFns {
16    const REGISTER_FNS: &'static [fn(registry: Registry) -> Registry];
17}
18
19pub trait TypeName: Register {
20    fn get_type_name() -> Cow<'static, str>;
21}
22
23pub trait OutputTypeName: TypeName {
24    fn get_output_type_name() -> Cow<'static, str> {
25        <Self as TypeName>::get_type_name()
26    }
27}
28
29pub trait InputTypeName: TypeName {
30    fn get_input_type_name() -> Cow<'static, str> {
31        <Self as TypeName>::get_type_name()
32    }
33}
34
35pub trait Object: OutputTypeName + ParentType {
36    fn get_object_type_name() -> Cow<'static, str> {
37        <Self as OutputTypeName>::get_output_type_name()
38    }
39}
40
41pub trait Enum: OutputTypeName {
42    fn get_enum_type_name() -> Cow<'static, str> {
43        <Self as OutputTypeName>::get_output_type_name()
44    }
45}
46
47pub trait Scalar: OutputTypeName + InputTypeName {
48    fn get_scalar_type_name() -> Cow<'static, str> {
49        <Self as TypeName>::get_type_name()
50    }
51}
52
53pub trait ScalarValue {
54    fn from_value(value: crate::Value) -> crate::Result<Self>
55    where
56        Self: Sized;
57    fn to_value(&self) -> crate::Value;
58}
59
60pub trait Union: OutputTypeName {
61    fn get_union_type_name() -> Cow<'static, str> {
62        <Self as OutputTypeName>::get_output_type_name()
63    }
64}
65
66pub trait Interface: OutputTypeName {
67    fn get_interface_type_name() -> Cow<'static, str> {
68        <Self as OutputTypeName>::get_output_type_name()
69    }
70}
71
72pub trait ParentType {
73    type Type: Object;
74}
75
76pub trait InterfaceMark<T: Interface + ?Sized> {}
77
78pub trait InputObject: InputTypeName {
79    fn get_input_object_type_name() -> Cow<'static, str> {
80        <Self as InputTypeName>::get_input_type_name()
81    }
82}
83
84pub trait Mutation: ExpandObject {}
85
86pub trait ExpandObject: ParentType {
87    fn get_expand_object_name() -> Cow<'static, str>;
88}
89
90pub trait GetOutputTypeRef {
91    fn get_output_type_ref() -> TypeRefBuilder;
92}
93
94pub trait GetInputTypeRef {
95    fn get_input_type_ref() -> TypeRefBuilder;
96}