entity_async_graphql/ent/
edge.rs1use async_graphql::{Enum, Object};
2use derive_more::{From, Into};
3use entity::{Edge, EdgeDeletionPolicy, EdgeValue, EdgeValueType, Id};
4
5#[derive(From, Into)]
7pub struct GqlEdge(Edge);
8
9#[Object]
10impl GqlEdge {
11 #[graphql(name = "name")]
12 async fn gql_name(&self) -> &str {
13 self.0.name()
14 }
15
16 #[graphql(name = "type")]
17 async fn gql_type(&self) -> GqlEdgeValueType {
18 GqlEdgeValueType::from(self.0.to_type())
19 }
20
21 #[graphql(name = "value")]
22 async fn gql_value(&self) -> GqlEdgeValue {
23 GqlEdgeValue::from(self.0.value().clone())
24 }
25
26 #[graphql(name = "ids")]
27 async fn gql_ids(&self) -> Vec<Id> {
28 self.0.to_ids()
29 }
30
31 #[graphql(name = "deletion_policy")]
32 async fn gql_deletion_policy(&self) -> GqlEdgeDeletionPolicy {
33 GqlEdgeDeletionPolicy::from(self.0.deletion_policy())
34 }
35}
36
37#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Enum)]
38#[graphql(remote = "EdgeDeletionPolicy")]
39pub enum GqlEdgeDeletionPolicy {
40 Nothing,
42
43 ShallowDelete,
46
47 DeepDelete,
50}
51
52#[derive(From, Into)]
54pub struct GqlEdgeValue(EdgeValue);
55
56#[Object]
57impl GqlEdgeValue {
58 #[graphql(name = "ids")]
59 async fn gql_ids(&self) -> Vec<Id> {
60 self.0.to_ids()
61 }
62
63 #[graphql(name = "type")]
64 async fn gql_type(&self) -> GqlEdgeValueType {
65 GqlEdgeValueType::from(self.0.to_type())
66 }
67}
68
69#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Enum)]
70#[graphql(remote = "EdgeValueType")]
71pub enum GqlEdgeValueType {
72 MaybeOne,
74 One,
76 Many,
78}