use async_graphql::{Enum, Object};
use derive_more::{From, Into};
use entity::{Edge, EdgeDeletionPolicy, EdgeValue, EdgeValueType, Id};
#[derive(From, Into)]
pub struct GqlEdge(Edge);
#[Object]
impl GqlEdge {
#[graphql(name = "name")]
async fn gql_name(&self) -> &str {
self.0.name()
}
#[graphql(name = "type")]
async fn gql_type(&self) -> GqlEdgeValueType {
GqlEdgeValueType::from(self.0.to_type())
}
#[graphql(name = "value")]
async fn gql_value(&self) -> GqlEdgeValue {
GqlEdgeValue::from(self.0.value().clone())
}
#[graphql(name = "ids")]
async fn gql_ids(&self) -> Vec<Id> {
self.0.to_ids()
}
#[graphql(name = "deletion_policy")]
async fn gql_deletion_policy(&self) -> GqlEdgeDeletionPolicy {
GqlEdgeDeletionPolicy::from(self.0.deletion_policy())
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Enum)]
#[graphql(remote = "EdgeDeletionPolicy")]
pub enum GqlEdgeDeletionPolicy {
Nothing,
ShallowDelete,
DeepDelete,
}
#[derive(From, Into)]
pub struct GqlEdgeValue(EdgeValue);
#[Object]
impl GqlEdgeValue {
#[graphql(name = "ids")]
async fn gql_ids(&self) -> Vec<Id> {
self.0.to_ids()
}
#[graphql(name = "type")]
async fn gql_type(&self) -> GqlEdgeValueType {
GqlEdgeValueType::from(self.0.to_type())
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Enum)]
#[graphql(remote = "EdgeValueType")]
pub enum GqlEdgeValueType {
MaybeOne,
One,
Many,
}